hedonomania Posted January 25, 2014 Share Posted January 25, 2014 Hi guys, I hav question concerning retriving the data from mysql. I set the following code, but as a result i am getting a single cells in one column. Instead I would like to get the results as the whole rows with the cells i'm looking for. Any help? Thanks in advance! $query_string="SELECT Type FROM $tablename WHERE name like'%$type%'"; $result_id=mysql_query($query_string,$mydb); $column_count=mysql_num_fields($result_id); print "<table border=1 align=center>\n"; $row=mysql_fetch_array($result_id); while ($row=mysql_fetch_array($result_id)) { print "<tr align=left valign=top>"; for ( $column_num=0; $column_num<$column_count; $column_num++) print "<td>$row[$column_num]</td>\n"; print "</tr>\n"; } print "</table>\n"; Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted January 25, 2014 Share Posted January 25, 2014 (edited) Open/close the <tr> (table rows) outside of the while loop? Edited January 25, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
Barand Posted January 25, 2014 Share Posted January 25, 2014 Do you mean print "<table border=1 align=center>\n"; print "<tr align=left valign=top>"; while ($row=mysql_fetch_array($result_id)) { print "<td>$row[0]</td>\n"; } print "</tr>\n"; print "</table>\n"; Quote Link to comment Share on other sites More sharing options...
hedonomania Posted January 25, 2014 Author Share Posted January 25, 2014 I think I didn't put my thoughts clearly i am getting my single column as a row now, which is not what i wanted. I would like to get the results from the searched field plus the associated values from other fields in the database. e.g. when i have the dabase composed of name and surname fields and i search the name field, and i get John, i want to get not only the name but also the surname so i want to see John Muller... thanks! Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 25, 2014 Share Posted January 25, 2014 Your query ONLY selects one column. Therefore, that is the ONLY column you will retrieve from your db. Seems like you need to change your query Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.