Jump to content

Mysql -> PHP array


otester

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.