cryp7 Posted March 26, 2006 Share Posted March 26, 2006 Ok i did a quick search like normal and cudnt find ne thingSo what im looking for is the script to search the "user" table for the row "characters" by the "username", and if the value found for the spefic user is "1" then it needs to say sorry cant do it etc. and if its "0" then it should let the rest happen[code]<?phpmysql_connect("localhost", "xxx", "xxx") ordie("Could not connect: " . mysql_error());mysql_select_db("xxx");$create = mysql_query("SELECT characters FROM users WHERE username='$username'");$results2 = mysql_query($create) or die(mysql_error());if (mysql_num_rows($results2) == 1) {die("You Already Have A Character, And Cant Make Another - Try Editing Your Character Instead <a href=\"character_edit.php\">Edit Here</a>");}if ($create == 0) {echo "So Therefore You Can Make One Here:";}?>[/code]Thats what i got so far - and i get...[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #19' at line 1[/quote]so help would be very much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/5845-if-using-table-data/ Share on other sites More sharing options...
toplay Posted March 26, 2006 Share Posted March 26, 2006 Example:[code]$create = "SELECT `characters` FROM `users` WHERE `username` = '$username' AND `characters` = '1'";$results2 = mysql_query($create) or die(mysql_error());if (mysql_num_rows($results2) > 0) {die("You Already Have A Character, And Cant Make Another - Try Editing Your Character Instead <a href=\"character_edit.php\">Edit Here</a>");} else { echo "So Therefore You Can Make One Here:";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5845-if-using-table-data/#findComment-20846 Share on other sites More sharing options...
slipperyfish Posted March 26, 2006 Share Posted March 26, 2006 well.. ur running the SQL query twice..[code]$create = mysql_query("SELECT characters FROM users WHERE username='$username'");$results2 = mysql_query($create) or die(mysql_error());[/code]$create = mysql_query...$result2 = mysql_query...Just have:[code]$create = "SELECT characters FROM users WHERE username='$username'"$results2 = mysql_query($create) or die(mysql_error());[/code]..Adam Quote Link to comment https://forums.phpfreaks.com/topic/5845-if-using-table-data/#findComment-20852 Share on other sites More sharing options...
kenrbnsn Posted March 26, 2006 Share Posted March 26, 2006 You're executing the function mysql_query() twice.[code]<?php$create = mysql_query("SELECT characters FROM users WHERE username='$username'");$results2 = mysql_query($create) or die(mysql_error());?>[/code]Do this instead:[code]<?php$create = "SELECT characters FROM users WHERE username='$username'";$results2 = mysql_query($create) or die('Problem with query: ' . $create . '<br>' . mysql_error());?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/5845-if-using-table-data/#findComment-20863 Share on other sites More sharing options...
cryp7 Posted March 26, 2006 Author Share Posted March 26, 2006 EDIT: Ok i worked out forms :Dnow waht i need to know is how to get values from a database so that i can put them into a drop down box on a formie. i want to find what items the user has that are "type" = "S" now to do this i need to search the "inventory" table for "item_id"s by "username", then seach "item" table by "item_id" to add a "name" etc to the "item_id" but i wanna sort these items by "type" "S"e.g. user admin has item_id 1,2 and 3 these are:1 - Blue Ball Skin - type "S"2 - Green Ball Skin - type "S"3 - Crazied Blob Skin - type "I"so i need values 1 and 2, selected and then a way to add them to a drop down list in a form...heres what i got so far:[code]<?phpmysql_connect("localhost", "xxx", "xxx") ordie("Could not connect: " . mysql_error());mysql_select_db("xxx");$allitems_id = mysql_query("SELECT id,item_id FROM inventory WHERE username='$username'");$row10 = mysql_fetch_array($allitems_id);$item_id = $row10['item_id'];$type = "S";$sitems_id = mysql_query("SELECT name,description,buy_price,sell_price,img_path FROM items WHERE item_id='$item_id' AND type='$type'");$row11 = mysql_fetch_array($sitems_id);printf ("Name: %s", $row11['name']);mysql_free_result($sitems_id);?>[/code]although this dosnts print the values, i think its on the right track...?any help welcome thxs Quote Link to comment https://forums.phpfreaks.com/topic/5845-if-using-table-data/#findComment-20864 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.