Jump to content

SQL Query loop


cry of war

Recommended Posts

I am trying to do a sql search for a item in my table. The query works the only problem is trying to display it now. everything works but when its in the while loop i dont understand how to make it call for the right variable for example i want it to call "$Ingredientlevel2" then next time i want to make it call "$Ingredientlevel3" how do i make it loop and make it call the next

 

 

here is part of my code:

 

$EditAlchemy=$_POST["EditAlchemy"];
$result = mysql_query("SELECT * FROM $table WHERE 'Ingredientname'='$EditAlchemy'");
$Ingredientname=mysql_query("SELECT Ingredientname FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientdis=mysql_query("SELECT Ingredientdis FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientweight=mysql_query("SELECT Ingredientweight FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientlevel1=mysql_query("SELECT Ingredientlevel1 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Effect1=mysql_query("SELECT Effect1 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Alignment1=mysql_query("SELECT Alignment1 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientstrenth1=mysql_query("SELECT Ingredientstrenth1 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientduration1=mysql_query("SELECT Ingredientduration1 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientlevel2=mysql_query("SELECT Ingredientlevel2 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Effect2=mysql_query("SELECT Effect2 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Alignment2=mysql_query("SELECT Alignment2 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientstrenth2=mysql_query("SELECT Ingredientstrenth2 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientduration2=mysql_query("SELECT Ingredientduration2 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientlevel3=mysql_query("SELECT Ingredientlevel3 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Effect3=mysql_query("SELECT Effect3 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Alignment3=mysql_query("SELECT Alignment3 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientstrenth3=mysql_query("SELECT Ingredientstrenth3 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientduration3=mysql_query("SELECT Ingredientduration3 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientlevel4=mysql_query("SELECT Ingredientlevel4 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Effect4=mysql_query("SELECT Effect4 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Alignment4=mysql_query("SELECT Alignment4 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientstrenth4=mysql_query("SELECT Ingredientstrenth4 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientduration4=mysql_query("SELECT Ingredientduration4 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientlevel5=mysql_query("SELECT Ingredientlevel5 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Effect5=mysql_query("SELECT Effect5 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Alignment5=mysql_query("SELECT Alignment5 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientstrenth5=mysql_query("SELECT Ingredientstrenth5 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientduration5=mysql_query("SELECT Ingredientduration5 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientlevel6=mysql_query("SELECT Ingredientlevel6 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Effect6=mysql_query("SELECT Effect6 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Alignment6=mysql_query("SELECT Alignment6 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientstrenth6=mysql_query("SELECT Ingredientstrenth6 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientduration6=mysql_query("SELECT Ingredientduration6 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientlevel7=mysql_query("SELECT Ingredientlevel7 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Effect7=mysql_query("SELECT Effect7 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Alignment7=mysql_query("SELECT Alignment7 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientstrenth7=mysql_query("SELECT Ingredientstrenth7 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientduration7=mysql_query("SELECT Ingredientduration7 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientlevel8=mysql_query("SELECT Ingredientlevel8 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Effect8=mysql_query("SELECT Effect8 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Alignment8=mysql_query("SELECT Alignment8 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientstrenth8=mysql_query("SELECT Ingredientstrenth8 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientduration8=mysql_query("SELECT Ingredientduration8 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientlevel9=mysql_query("SELECT Ingredientlevel9 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Effect9=mysql_query("SELECT Effect9 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Alignment9=mysql_query("SELECT Alignment9 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientstrenth9=mysql_query("SELECT Ingredientstrenth9 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientduration9=mysql_query("SELECT Ingredientduration9 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientlevel10=mysql_query("SELECT Ingredientlevel10 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Effect10=mysql_query("SELECT Effect10 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Alignment10=mysql_query("SELECT Alignment10 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientstrenth10=mysql_query("SELECT Ingredientstrenth10 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
$Ingredientduration10=mysql_query("SELECT Ingredientduration10 FROM Ingredient WHERE Ingredientname='$EditAlchemy'");
echo "<tr><td>Alchemy Ingredient name:</td><td><input type='text' name='Ingredientname' value='".$Ingredientname."' maxlength='30'></td></tr>";
echo "<tr><td>Ingredient description:</td><td><textarea name='Ingredientdis' maxlength='256'>".$Ingredientdis."</textarea></td></tr>";
echo "<tr><td>Weight of Ingredient:</td><td><input type='text' name='Ingredientweight' value='".$Ingredientweight."' maxlength='6'></td></tr>";
echo "</table>";
echo "<table>";
$i=0;
$maxnumber=10;
While($i<$maxnumber){
$i++;
echo "<tr><td>Level required<br>to identify Effect:</td><td><input type='text' name='Ingredientlevel".$i."' value='".$Ingredientlevel.$i."' maxlength='3' size='2'></td>\n";
echo "<td>Effect:\n";
echo "<td><select name='Effect" .$i. "'>\n";
while ($row1 = mysql_fetch_array($result2, MYSQL_BOTH)) {
echo "<option value" .$row1[Name]. "";
if ($row1[Name]==$Effect.$i){
echo "selected";
}
echo ">" .$row1[Name]. "<option>\n";
}
echo "</select></td>";
echo "<td>Effect Strength:\n";
echo "<select name='Alignment" .$i. "'>\n";
if ($Alignment.$i=="1"){
$yes="selected";
$no="";
}else{
$no="selected";
$yes="";
}
echo "<option value='1' ".$yes.">+</option>\n";
echo "<option value='2' ".$no.">-</option>\n";
echo "</select></td>\n";
echo "<td><input type='text' name='Ingredientstrenth" .$i. "' value='".$Ingredientstrenth."".$i."' maxlength='3' size='2'></td>\n";
echo "<td>Duration:</td><td><input type='text' name='Ingredientduration" .$i. "' value='".$Ingredientduration.$i."' maxlength='3' size='2'>(seconds)</td></tr>\n";

 

Link to comment
Share on other sites

Wow...

 

Did you make a different table for... everything?

 

You might want to ... I mean, you could make a table called items, and put everything in it - and only make one query and loop it. Performance wise you don't want to make that many queries...

 

I've never seen so many queries... that must have taken forever...

 

You might want to look into classes - normally I don't recommend using them due to the general nature of web scripts, but the way you are creating items with properties it probably would be a good use for them.

Link to comment
Share on other sites

Wow...

 

Did you make a different table for... everything?

 

tibberous,

 

If you look closely you'll see every query is on the same table and where clause. Its just that each one selects a different individual column.

 

The amazing part is the statement "everything works"

 

 

cry of war,

$Ingredientname=mysql_query("SELECT Ingredientname FROM Ingredient WHERE Ingredientname='$EditAlchemy'");

 

This does NOT put the value of Ingredientname into $Ingredientname.

I recommend you go back to the php manual and closely read the mysql functons section and the examples there.

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.