paegn Posted May 30, 2010 Share Posted May 30, 2010 I'm going to start by apologizing.... I'm sure this has been asked and answered before, but I've been searching all day and I'm not having any luck. I've set up a Mysql database for product specs. There are about 70 fields at the moment, but this will likely increase. Basically, I need to be able to select 2 records, and display them side by side in 2 columns. I'm sending: $a = 1; $b = 72; $result=mysql_query(SELECT * FROM `fixtures` WHERE id = ".$a." OR id = ".$b); $row = mysql_fetch_array($result); I've had a look at the result using phpmyadmin, and the query is returning 2 recors, as it should. When I try get the data for the second record, I'm getting stumped... If I use mysql_num_rows($result); I'm seeing 2 records, but I can't see it using var_dump($row); $row[1]['id'] isn't working, either. What am I doing wrong? I'd also like to be able to access the field names as well, so I can create a function that will be reusable throughout the whole table. In order to keep everything laid out correctly, I'm using a containing <div> then floating 3 <div>'s inside it. the first one being the field name in readable english, the second 2 being the data from the records. Ideally, I'd like to be able to list 3 or 4 products as well. I'm sure it's something simple that I'm missing, probably to do with the arrave variable, but as I said, I've been trying to sort this out all day, and my brain is fried now. thanks in advance. martin Link to comment https://forums.phpfreaks.com/topic/203343-mysql-results-in-variable/ Share on other sites More sharing options...
kenrbnsn Posted May 30, 2010 Share Posted May 30, 2010 The function mysql_query returns a pointer to the results set. To get all the results you need to use a fetch function in a loop; <?php $q = "SELECT * FROM `fixtures` WHERE id = ".$a." OR id = ".$b; $result=mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); while ($row = mysql_fetch_assoc($result)) { echo '<pre>' . print_r($row) . '</pre>'; } ?> Ken Link to comment https://forums.phpfreaks.com/topic/203343-mysql-results-in-variable/#findComment-1065322 Share on other sites More sharing options...
paegn Posted May 30, 2010 Author Share Posted May 30, 2010 Thanks Ken. Using this method, am I able to access the 'key' and 'value' info for each record? I keep thinking that I need to load the record info into a variable array so I can get the data formatted as I need. Cheers. Martin Link to comment https://forums.phpfreaks.com/topic/203343-mysql-results-in-variable/#findComment-1065354 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.