Jump to content

Question about combinding multiple mysql_querys


vet911

Recommended Posts

I have this code below when run gets the total number of rows for each item I require. I was wondering if there is an easier way to do this or is my way okay for what I doing?  It works but I thinking there might be a faster way to do this.

Any suggestions will be appreciated.

I thank you in advance for your help.

<?php
include 'config.php';

// Connect to server and select database.
mysql_connect($dbhost, $dbuser, $dbpass)or die("cannot connect");
mysql_select_db("jtovey")or die("cannot select DB");

$result0 = mysql_query("SELECT * FROM $dbname WHERE ring = '1'");
  $rows0 = mysql_num_rows($result0);
  // results
  $result1 = mysql_query("SELECT * FROM $dbname WHERE earrings = '1'");
  $rows1 = mysql_num_rows($result1);
  // results
  $result2 = mysql_query("SELECT * FROM $dbname WHERE pendant = '1'");
  $rows2 = mysql_num_rows($result2);
  // results
  $result3 = mysql_query("SELECT * FROM $dbname WHERE cab = '1'");
  $rows3 = mysql_num_rows($result3);
  // results
  $result4 = mysql_query("SELECT * FROM $dbname WHERE bead = '1'");
  $rows4 = mysql_num_rows($result4);
  
  $result5 = mysql_query("SELECT * FROM $dbname WHERE new = '1'");
  $rows5 = mysql_num_rows($result5);

$result = mysql_query("SELECT * FROM $dbname WHERE  sold = '0' ORDER BY new DESC, itemno ASC" ) or die(mysql_error());
// store the record of the "" table into $row
$current = '';

// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
$id = $row['id'];
$new = $row['new'];
if (!$current) {
echo "<center><div><table border='0' width='520'>";
$current = $id;
echo "<img src='images/too_jewelry.png' alt='too'/><br/>";
echo "<div>";
	echo "<b>Too is a direct Gemstone & Jewelry manufacturing source for the trade.</b><br/>";
	echo "</div>";
	echo "<div>";
	echo "Questions about store items use link in menu.<br/>";
	echo "Latest (".$rows5.") ";
	echo "Beads (".$rows4.") ";
	echo "Cabochons (".$rows3.") ";
echo "Earrings (".$rows1.") ";
echo "Pendants (".$rows2.") ";
echo "Rings (".$rows0.") ";
    echo "</div>";
    echo "<p><b>Click picture to enlarge.</b></p>";
echo "<hr width='520'>";
} elseif ($current != $id){
echo "</table></div><br><div><table border='0' width='520'>";
$current = $id;
echo "<hr width='520'>";
}
?>

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.