butsags Posted October 16, 2009 Share Posted October 16, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/177927-solved-how-to-code-this-in-mysql-and-php/ Share on other sites More sharing options...
kickstart Posted October 16, 2009 Share Posted October 16, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/177927-solved-how-to-code-this-in-mysql-and-php/#findComment-938135 Share on other sites More sharing options...
butsags Posted October 16, 2009 Author Share Posted October 16, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/177927-solved-how-to-code-this-in-mysql-and-php/#findComment-938149 Share on other sites More sharing options...
butsags Posted October 16, 2009 Author Share Posted October 16, 2009 also in mysql 'query amount' isnt one of my columns unless this is a function to get the amount which i dont think it is? Quote Link to comment https://forums.phpfreaks.com/topic/177927-solved-how-to-code-this-in-mysql-and-php/#findComment-938165 Share on other sites More sharing options...
kickstart Posted October 16, 2009 Share Posted October 16, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/177927-solved-how-to-code-this-in-mysql-and-php/#findComment-938166 Share on other sites More sharing options...
butsags Posted October 16, 2009 Author Share Posted October 16, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/177927-solved-how-to-code-this-in-mysql-and-php/#findComment-938174 Share on other sites More sharing options...
kickstart Posted October 16, 2009 Share Posted October 16, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/177927-solved-how-to-code-this-in-mysql-and-php/#findComment-938176 Share on other sites More sharing options...
butsags Posted October 16, 2009 Author Share Posted October 16, 2009 thanks so much man ive been working on this dang script for like 2 freaking days just trying random combinations haah it works great Quote Link to comment https://forums.phpfreaks.com/topic/177927-solved-how-to-code-this-in-mysql-and-php/#findComment-938182 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.