Jump to content

[SOLVED] How to code this in mysql and php?


Recommended Posts

Okay so i has a start already.

 

 

$query = mysql_query("SELECT * FROM inventoryitems WHERE characterid = '$id' AND inventorytype = -1  AND position = -101");
while($row = mysql_fetch_array($query)){
$equipt = $row[itemid];
echo "
<img src=\"http://www.mapletip.com/images/maplestory-monsters/0$equipt.png\">";
}					

 

 

 

I would like to somehow say, if there is no item that qualifies the specifications of $query , then to show <img src="images/none.png">

 

 

sorry i barely know any mysql implementing

 

i guess it would have to be something like

 

IF $query amount > 0 {
echo "
<img src=\"http://www.mapletip.com/images/maplestory-monsters/0$equipt.png\">
";
} else {
echo " 
<img src=\"images/none.png\">";
}

 

but i just don't know how to correctly say that.

 

I would be extremely grateful for any help.

 

thanks

Hi

 

You were close

 

Assuming query_amount is a column brought back by the query:-

 

$query = mysql_query("SELECT * FROM inventoryitems WHERE characterid = '$id' AND inventorytype = -1  AND position = -101");
while($row = mysql_fetch_array($query))
{
$equipt = $row[itemid];
if ($row['query amount'] > 0) 
{
	echo "<img src='http://www.mapletip.com/images/maplestory-monsters/".$equipt.".png'>";
} 
else 
{
	echo "<img src='images/none.png'>";
}
}	

 

All the best

 

Keith

hey there :)

 

alright so i tried adding it in as you specified and it wasnt showing up either the none image or the other image.

 

so i played around with it and i got the first image to show up:

$query = mysql_query("SELECT * FROM inventoryitems WHERE characterid = '$id' AND inventorytype = -1  AND position = -101");
while($row = mysql_fetch_array($query))
{
   $equipt = $row[itemid];
   if ($row['query amount'] = 1)
   {
      echo "<img src=\"http://www.mapletip.com/images/maplestory-monsters/0$equipt.png\">";
   }
   else
   {
      echo "<img src=\"http://ingis.com/butsagsms/images/none.png\">";
   }
}

 

sorry i formatted it a little differently in a few sections to see if that as why it wasnt working.

 

adding

  if ($row['query amount'] = 1)

fixed the first image but when i change this :

$query = mysql_query("SELECT * FROM inventoryitems WHERE characterid = '$id' AND inventorytype = -1  AND position = -101");

to this:

$query = mysql_query("SELECT * FROM inventoryitems WHERE characterid = '$id' AND inventorytype = -1  AND position = -2");

 

it doesnt bring up the none.png

this SHOULD bring up the second image because the query amount is none then.

 

but it doesnt.

 

so i then thought it was the link to the second image so i direct linked it.

 

if you put the link in your browser you can see it works.

 

if it helps at all, the page im working with is here:

http://ingis.com/butsagsms/?butsags=main&page=player&name=cygnushero

 

i have it set to  position = -101 so as you can see the "hat" image comes up (look to the equipment inventory image)

 

 

 

 

------------EDIT-----------------

 

ok i was fooling around further and when i change

  if ($row['query amount'] = 1)

 

to

 

  if ($row['query amount'] > 0)

the none image shows up.

 

 

so i think the problem lies in that row.

 

so i think that the problem is that in that row, i think we need to specify that if the query amount is 1 then the first image shows and if its 0 then the none.png shows

 

any ideas?

Hi

 

Is the row on the table called  query amount. It must match. Or are you trying to get the number of rows returned?

 

What field do you want to use to determine which row to output? Or to you want to ouput the first if any row is returned and the 2nd is no row is returned?

 

The problem you have added is that if ($row['query amount'] = 1) is mainly just assigning 1 to $row['query amount'].

 

All the best

 

Keith

hey alright i am trying to find out if there is a row with the characteristics defined in $query.

 

and the if /else statement has to specify that if there is a row with inventorytype = -1 and position = -101 then output this:

{
echo "<img src=\"http://www.mapletip.com/images/maplestory-monsters/0$equipt.png\">";
}

but if it cannot find a row with those characteristics then start:

{
echo "<img src='http://ingis.com/butsagsms/images/none.png'>";
}

 

sorry if i threw you off in any way.

 

Hi

 

OK, should be simple like this:-

 

$query = mysql_query("SELECT * FROM inventoryitems WHERE characterid = '$id' AND inventorytype = -1  AND position = -101");
if($row = mysql_fetch_array($query))
{
$equipt = $row['itemid'];
echo '<img src="http://www.mapletip.com/images/maplestory-monsters/'.$equipt.'.png">';
}
else
{
echo '<img src="http://ingis.com/butsagsms/images/none.png">';
}

 

Basically if any rows are returned the if will succeed, otherwise the else will be processed.

 

All the best

 

Keith

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.