OriginalSunny Posted March 25, 2006 Share Posted March 25, 2006 That code output the the row titles below each other so unfortunately did not work. I have found a way to make it output how i want to using this code:[b]$query = "select * from orders"; $result = mysql_query($query,$connect) or die("sql_del: ".mysql_error($connect));$query1 = "select * from orders"; $result1 = mysql_query($query1,$connect) or die("sql_del: ".mysql_error($connect));[/b]echo "<table border='2' cellpadding='5'>\n";echo "<tr><td>orderID</td>";while($row = mysql_fetch_array($result)) { echo "<td>"; echo ''.$row['orderID'].''; echo "</td>";}echo "</tr>";echo "<tr><td>Title</td>";[i]while($row = mysql_fetch_array($result1)) { echo "<td>"; echo ''.$row['title'].''; echo "</td>";}echo"</tr>";[/i]echo '</table>';The only problem i am having with this way is that as you can see the code highlighted in bold is repetitive but if i dont use the second part of code, the code highlighted in italic does nothing. (If i use result instead of result1). Why is it that i can only use [i]result[/i] in the array once?? As i have a nuber of columns i am going to have to do this a number of times but i shouldnt need to should i?? Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted March 25, 2006 Share Posted March 25, 2006 if you've already gone through all the results with a while loop, then you can just use mysql_data_seek to go back to the start.[code]mysql_data_seek($result, 0);[/code][a href=\"http://www.php.net/mysql_data_seek\" target=\"_blank\"]http://www.php.net/mysql_data_seek[/a] Quote Link to comment Share on other sites More sharing options...
OriginalSunny Posted March 25, 2006 Author Share Posted March 25, 2006 I am trying to use that but it doesnt seem to work. The page doesn't load and just crashes. Am i using it wrong?while($row = mysql_data_seek($result,0)) { echo "<td>"; echo ''.$row['title'].''; echo "</td>";}echo"</tr>"; Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted March 26, 2006 Share Posted March 26, 2006 [!--quoteo(post=358330:date=Mar 25 2006, 07:53 PM:name=OriginalSunny)--][div class=\'quotetop\']QUOTE(OriginalSunny @ Mar 25 2006, 07:53 PM) [snapback]358330[/snapback][/div][div class=\'quotemain\'][!--quotec--]I am trying to use that but it doesnt seem to work. The page doesn't load and just crashes. Am i using it wrong?while($row = mysql_data_seek($result,0)) { echo "<td>"; echo ''.$row['title'].''; echo "</td>";}echo"</tr>";[/quote]yes you're using it wrong here. what data seek does is returns the internal pointer to 0 or wherever you specify. so for example:[code]$query = "select * from thistable";$result = mysql_query($query) or die('Whoops - '.mysql_error());while ($row = mysql_fetch_assoc($result){ echo $row['Name'];}mysql_data_seek($result, 0);while ($row = mysql_fetch_assoc($result){ echo $row['Name'];}[/code]the above will print the same set of information twice without using two seperate queries/results.on a sidenote, the reason why your browser crashed with the code you used is because mysql_data_seek returns true if it's successful. As it had no problem working, it was always true so your while loop carried on going...and going...Hope that helpsCheersMark 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.