You are here: Re: Newbie: How to display query result in table? « PHP Programming Language « IT news, forums, messages
Re: Newbie: How to display query result in table?

Posted by IchBin on 12/17/87 11:52

william.clarke wrote:
> IchBin wrote:
>> IchBin wrote:
>>> Gulasch wrote:
>>>> IchBin wrote:
>>>>> flamer die.spam@hotmail.com wrote:
>>>>>> <table>
>>>>>> <tr>
>>>>>> <?php
>>>>>> $query = mysql_query(select blah..);
>>>>>> echo '<td>'.$query.'</td>';
>>>>>> ?>
>>>>>> </tr>
>>>>>> </table>
>>>>>>
>>>>>> now i assume your pulling multiple rows so you need a "while"
>>>>>> statement, read up on them in the manual php.net they are simple to
>>>>>> use, and excuse the psuedo code.
>>>>>>
>>>>>> flamer.
>>>>>>
>>>>>> Huevos wrote:
>>>>>>
>>>>>>> I scanned through hundreds of posts and tried several variations on
>>>>>>> some
>>>>>>> promising posts, but have not succeeded yet... All I want to do (to
>>>>>>> start)
>>>>>>> is have a web page display a table of the result of a query.
>>>>>>>
>>>>>>> I am using MySQL via geocities.yahoo.com. The MySQLAdmin auto
>>>>>>> generated a
>>>>>>> PHP version of my query as follows:
>>>>>>>
>>>>>>> $sql = 'SELECT * FROM `Varieties` WHERE 1'
>>>>>>> . ' ORDER BY `nHeight` DESC, `nDiameter` DESC, `nMinTemp` ASC,
>>>>>>> `tSun` DESC LIMIT 0, 30 ';
>>>>>>>
>>>>>>>
>>>>>>> I tried to merge this into code from another suggestion in these
>>>>>>> groups and
>>>>>>> came up with:
>>>>>>>
>>>>>>> <HTML>
>>>>>>> <HEAD>
>>>>>>> </HEAD>
>>>>>>> <BODY>
>>>>>>> <?
>>>>>>> // DATABASE QUERY
>>>>>>> $bamboo='SELECT * FROM `Varieties` WHERE 1'
>>>>>>> . ' ORDER BY `nHeight` DESC, `nDiameter` DESC, `nMinTemp` ASC,
>>>>>>> `tSun` DESC LIMIT 0, 30 ';
>>>>>>> $result= mysql_query($bamboo);
>>>>>>> ?>
>>>>>>>
>>>>>>> <table width="100%" border="0" cellspacing="0" cellpadding="0">
>>>>>>> <tr>
>>>>>>> <td>LINK 1 DETAILS HERE<br>
>>>>>>> DATABASE QUERY: <? $result; ?></td>
>>>>>>> </tr>
>>>>>>> </table>
>>>>>>> <? } ?>
>>>>>>> </BODY>
>>>>>>> </HTML>
>>>>>>>
>>>>>>> Can anyone offer a suggestion?
>>>>>>> Thanks in advance!
>>>>>>>
>>>>>>> Jeff Hawkins
>>>>> Not to add another question to this question but how would this be
>>>>> done with a dropdown list?
>>>>>
>>>>> Thanks in Advance...
>>>>> IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
>>>>> __________________________________________________________________________
>>>>>
>>>>>
>>>>> 'If there is one, Knowledge is the "Fountain of Youth"'
>>>>> -William E. Taylor, Regular Guy (1952-)
>>>> If you have let's say
>>>>
>>>> --snip--
>>>> $sql="SELECT field FROM table";
>>>> $result=mysql_query($sql, $connection);
>>>> --snap--
>>>>
>>>> you could do for example
>>>>
>>>> --snip--
>>>> echo "<select size=1>";
>>>> while($row=mysql_fetch_assoc($result))
>>>> {
>>>> echo "<option>". $row['field'] ."</option>";
>>>> }
>>>> echo "</select>";
>>>> --snap--
>>>>
>>>> to get a Drop-Down-List.
>>> Thank you so much...
>>>
>> Thanks again.. I am able to load and display the dropdownlist.
>>
>> Not sure why but I still had a problem with using:
>>
>> echo "<option>".$row['field']."</option>";
>>
>> But can get to work using this statement:
>>
>> echo "<select size=10>";
>> while ($row = mysql_fetch_object($result)) {
>> echo "<option>".$row->field."</option>";
>> }
>> echo "</select>";
>>
>>
>> Thanks in Advance...
>> IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
>> __________________________________________________________________________
>>
>> 'If there is one, Knowledge is the "Fountain of Youth"'
>> -William E. Taylor, Regular Guy (1952-)
>
>
> Because you fetched an object using this statement
> while ($row = mysql_fetch_object($result))
> rather than an associative array using this statement:
> while($row=mysql_fetch_assoc($result))
>
> as a result this works: $row->field
> and this doesn't: $row['field']
>

Thank you for you explanation..

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация