solon Posted December 19, 2008 Share Posted December 19, 2008 Hey guys this is a bit complicated but i ll try to explain as good as i can. I have a table with lets say the following values: type value something something2 1 111 something something2 2 222 something something2 3 333 something something2 ..... .... ...... .......... 1000 1010101010 something something2 Instead of displaying the values using $qry = mysql_query("select * from ..."); $row = mysql_fetch_array($qry); echo $row[type]; i want to access the values of field 'type' , like: $qry = mysql_query("select * from ..."); $row = mysql_fetch_array($qry); echo $row[1]; echo $row[2]; echo $row[1000]; and actually display the values of 'value' , 'something', 'something2' I hope you get my point, Thanks in advance Link to comment https://forums.phpfreaks.com/topic/137706-solved-query-problems/ Share on other sites More sharing options...
premiso Posted December 19, 2008 Share Posted December 19, 2008 <?php $qry = mysql_query("select * from ..."); while ($row = mysql_fetch_assoc($qry)) { $types[] = $row['type'] . ", " . $row['value'] . ", " . $row['something'] . ", " . $row['something2']; } $cnt = count($types); for ($i=0; $i<$cnt; $i++) { echo $type[$i] . "<Br />"; } ?> Should do the trick. Or without the for loop: <?php $qry = mysql_query("select * from ..."); while ($row = mysql_fetch_assoc($qry)) { echo $row['type'] . ", " . $row['value'] . ", " . $row['something'] . ", " . $row['something2'] . "<br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/137706-solved-query-problems/#findComment-719786 Share on other sites More sharing options...
solon Posted December 19, 2008 Author Share Posted December 19, 2008 thnx for the reply i will check it and let you know:) Link to comment https://forums.phpfreaks.com/topic/137706-solved-query-problems/#findComment-719788 Share on other sites More sharing options...
solon Posted December 19, 2008 Author Share Posted December 19, 2008 thnx premiso... I think with a few modifications it will work perfectly... Thanks again! Link to comment https://forums.phpfreaks.com/topic/137706-solved-query-problems/#findComment-719813 Share on other sites More sharing options...
premiso Posted December 19, 2008 Share Posted December 19, 2008 Not a problem. Just remember <?php $qry = mysql_query("select * from ..."); while ($row = mysql_fetch_assoc($qry)) { echo $row['type'] . ", " . $row['value'] . ", " . $row['something'] . ", " . $row['something2'] . "<br />"; } ?> Is pretty much the basis for looping through query data. Link to comment https://forums.phpfreaks.com/topic/137706-solved-query-problems/#findComment-719818 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.