otester Posted August 17, 2010 Share Posted August 17, 2010 My current code lists between 1-6 results from a MySQL array. How do I extract the data from the list and put it into its own variable (eg: $result1, $result2 etc.) ? $ran_x = rand(1,6); $ran_x = rand(1,6); $x_query = "SELECT * FROM `x` ORDER BY RAND( ) LIMIT $ran_x"; $get_x = mysql_query($appearance_query); echo 'x(s): '; echo '<br />'; while($row = mysql_fetch_array($get_x)) { echo $row['Appearance']; } Any help would be great, Thanks, otester Quote Link to comment https://forums.phpfreaks.com/topic/210958-mysql-php-array/ Share on other sites More sharing options...
Adam Posted August 17, 2010 Share Posted August 17, 2010 Within the loop just store the result into an array: $result = array(); while($row = mysql_fetch_array($get_x)) { $result[] = $row; } Quote Link to comment https://forums.phpfreaks.com/topic/210958-mysql-php-array/#findComment-1100326 Share on other sites More sharing options...
otester Posted August 17, 2010 Author Share Posted August 17, 2010 Within the loop just store the result into an array: $result = array(); while($row = mysql_fetch_array($get_x)) { $result[] = $row; } How do I extract each of the results from the array though? My goal is to be able to list results a delete individual results on the page with jQuery if the user needs to and I was going to do this by putting each result between <div> tags. Quote Link to comment https://forums.phpfreaks.com/topic/210958-mysql-php-array/#findComment-1100333 Share on other sites More sharing options...
JasonLewis Posted August 17, 2010 Share Posted August 17, 2010 Why not just do it in the loop. while($row = mysql_fetch_array($get_x)){ echo <<<html <div> <a href="javascript: void(0)" onclick="javascript: jQueryDelete('{$row['id']}')">Delete Record</a> | List other stuff. </div> html; } Quote Link to comment https://forums.phpfreaks.com/topic/210958-mysql-php-array/#findComment-1100336 Share on other sites More sharing options...
otester Posted August 17, 2010 Author Share Posted August 17, 2010 Why not just do it in the loop. while($row = mysql_fetch_array($get_x)){ echo <<<html <div> <a href="javascript: void(0)" onclick="javascript: jQueryDelete('{$row['id']}')">Delete Record</a> | List other stuff. </div> html; } The button doesn't do anything visually. Btw I don't mean delete from the database I mean just off the screen, basically my web page just lists stuff and users can either choose to keep an item, delete or replace it with another random one. Quote Link to comment https://forums.phpfreaks.com/topic/210958-mysql-php-array/#findComment-1100342 Share on other sites More sharing options...
otester Posted August 17, 2010 Author Share Posted August 17, 2010 Is there a way to add a unique div ID for each result? Quote Link to comment https://forums.phpfreaks.com/topic/210958-mysql-php-array/#findComment-1100360 Share on other sites More sharing options...
JasonLewis Posted August 17, 2010 Share Posted August 17, 2010 Use an incrementing value. Example: $i = 0; while($row = mysql_fetch_array($get_x)){ echo $i . '<br />'; $i++; } Just use $i in your div id, like: echo <<<html <div id="div_unique_{$i}"> ... stuff here ... </div> html; Quote Link to comment https://forums.phpfreaks.com/topic/210958-mysql-php-array/#findComment-1100385 Share on other sites More sharing options...
otester Posted August 17, 2010 Author Share Posted August 17, 2010 Use an incrementing value. Example: $i = 0; while($row = mysql_fetch_array($get_x)){ echo $i . '<br />'; $i++; } Just use $i in your div id, like: echo <<<html <div id="div_unique_{$i}"> ... stuff here ... </div> html; Works now! Thank you very much and to everyone else who posted! Quote Link to comment https://forums.phpfreaks.com/topic/210958-mysql-php-array/#findComment-1100463 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.