Jump to content

Selecting parts of an extracted MySQL array row


otester

Recommended Posts

Currently my code picks a random number between 1-6 then extracts that many (random) entries from a list in my database.

 

My current code displays the whole array, how can I chop the array into 6 bits so I can output the data separately (up to 6 list items)?

 

$con = mysql_connect("x","x","x");
	if (!$con)
  		{
  		die('Could not connect: ' . mysql_error());
  		}

	mysql_select_db("x", $con);

	$ran_x = rand(1,6);
	$appearance_query = "SELECT * FROM  `x` ORDER BY RAND( ) LIMIT $ran_x";
	$get_x = mysql_query($x_query);

	echo 'x(s): ';
	echo '<br />';
	echo "<ul style='list-style:none;'>";

	while($row = mysql_fetch_array($get_x))
  		{
	echo "<li>" . $row['x'] . "</li>";
  		}

	echo "</ul>";
	echo "<br />";

	mysql_close($con);

 

Any help would be greatly appreciated,

 

Thanks,

 

otester

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.