bob2588 Posted July 6, 2009 Share Posted July 6, 2009 i need some help on a script that i have never done i want to make a search code that seach a data base, there are a couple of virables that i have (type, state , zip , price range )and a few more but i have no idea how to write the script thank you Link to comment https://forums.phpfreaks.com/topic/164969-some-help/ Share on other sites More sharing options...
seventheyejosh Posted July 6, 2009 Share Posted July 6, 2009 like so? $res=mysql_query("SELECT * FROM `table` WHERE `name` LIKE '%$name%' && `age` LIKE '%$age%' && `location` LIKE '%$location%' ORDER BY `id` DESC"); http://www.w3schools.com/SQl/sql_like.asp http://www.w3schools.com/SQl/sql_wildcards.asp Link to comment https://forums.phpfreaks.com/topic/164969-some-help/#findComment-869864 Share on other sites More sharing options...
bob2588 Posted July 7, 2009 Author Share Posted July 7, 2009 i still have no idea how i would list the results. i under stnad how to do the mysql query now Link to comment https://forums.phpfreaks.com/topic/164969-some-help/#findComment-870087 Share on other sites More sharing options...
seventheyejosh Posted July 7, 2009 Share Posted July 7, 2009 i just posted this on another post you'll do $res=mysql_query($query); while($row=mysql_fetch_assoc($res)){ $touser=$row['touser']; $fromuser=$row['fromuser']; $comment=$row['comment']; $commentdate=$row['commentdate']; $commentid=$row['commentid']; echo "TO: $touser FROM: $fromuser\n"; echo "COMMENT: $comment\n"; echo "SENT ON: $commentdate\n"; echo "ID OF: $commentid\n"; echo "<br />\n"; } then for each iteration it'll update the variables from the db basically you do a query, and store the result in $res, then while $row is being gotten from $res, you loop through the array, getting a new row for each iteration Link to comment https://forums.phpfreaks.com/topic/164969-some-help/#findComment-870094 Share on other sites More sharing options...
bob2588 Posted July 7, 2009 Author Share Posted July 7, 2009 so it should look like this <?php mysql_connect('localhost', 'bob_2search', 'skater22') or die('Could not connect: ' . mysql_error()); $query = "("("SELECT * FROM real WHERE * LIKE '%$State%' && `zip` LIKE '%$zip%' && `Type` LIKE '%$type%' "); $res = mysql_query($qurey); while($row=mysql_fetch_assoc($res)){ $State=$row['State'] $zip=$row['zip'] $type=$row['type'] echo '<table align="center" cellspacing="10" cellpadding="15"> <tr> <td align="left"><b>Satet</b></td> <td align="left"><b>Zip</b></td> <td align="left"><b>Type</b></td> '; echo '<tr><td align="left">' . $row['custID'] . '</td> <td align="left">' . $row['State'] . '</td> <td align="left">' . $row['zip'] . '</td> <td align="left">' . $row['type'] . '</td> <</tr>'; } Link to comment https://forums.phpfreaks.com/topic/164969-some-help/#findComment-870108 Share on other sites More sharing options...
seventheyejosh Posted July 7, 2009 Share Posted July 7, 2009 i just glanced cause im tired from cutting the grass :\ but ya Link to comment https://forums.phpfreaks.com/topic/164969-some-help/#findComment-870128 Share on other sites More sharing options...
bob2588 Posted July 7, 2009 Author Share Posted July 7, 2009 All Right i will make the html part of it and give it a try Link to comment https://forums.phpfreaks.com/topic/164969-some-help/#findComment-870129 Share on other sites More sharing options...
bob2588 Posted July 7, 2009 Author Share Posted July 7, 2009 i am getting two errors one is Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/bob2/public_html/Search/search.php on line 41 the other is Parse error: syntax error, unexpected '{' in /home/bob2/public_html/Search/search.php on line 34 here is the code thank you for helping <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 1</title> </head> <body> <form method="POST" action="?go"> <p style="margin-top: 0; margin-bottom: 0"> </p> <p style="margin-top: 0; margin-bottom: 0"> <input type="text" name="State" size="20">State</p> <p style="margin-top: 0; margin-bottom: 0"> <input type="text" name="Zip" size="20">Zip</p> <p style="margin-top: 0; margin-bottom: 0"> <input type="text" name="Type" size="20">Type</p> <p style="margin-top: 0; margin-bottom: 0"> <input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p> </form> </body> </html> <?php if(isset($_GET['go']){ mysql_connect('localhost', 'bob2_search', 'skater22') or die('Could not connect: ' . mysql_error()); $query = ("SELECT * FROM real WHERE * LIKE '%$State%' && `zip` LIKE '%$zip%' && `Type` LIKE '%$type%' "); $res = mysql_query($qurey); while($row=mysql_fetch_assoc($res)){ $State=$row['State']; $zip=$row['zip']; $type=$row['type']; echo '<table align="center" cellspacing="10" cellpadding="15"> <tr> <td align="left"><b>Satet</b></td> <td align="left"><b>Zip</b></td> <td align="left"><b>Type</b></td> '; echo '<tr><td align="left">' . $row['custID'] . '</td> <td align="left">' . $row['State'] . '</td> <td align="left">' . $row['zip'] . '</td> <td align="left">' . $row['type'] . '</td> <</tr>'; } } Link to comment https://forums.phpfreaks.com/topic/164969-some-help/#findComment-870148 Share on other sites More sharing options...
seventheyejosh Posted July 7, 2009 Share Posted July 7, 2009 $query = ("SELECT * FROM real WHERE * LIKE '%$State%' && `zip` LIKE '%$zip%' && `Type` LIKE '%$type%' "); should be $query = ("SELECT * FROM real WHERE `state` LIKE '%$State%' && `zip` LIKE '%$zip%' && `Type` LIKE '%$type%' "); or watever ur state field is Link to comment https://forums.phpfreaks.com/topic/164969-some-help/#findComment-870163 Share on other sites More sharing options...
seventheyejosh Posted July 7, 2009 Share Posted July 7, 2009 k give this a go and remember to check against the table names of your DB <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 1</title> </head> <body> <form method="POST" action="?go"> <p style="margin-top: 0; margin-bottom: 0"> </p> <p style="margin-top: 0; margin-bottom: 0"> <input type="text" name="State" size="20">State</p> <p style="margin-top: 0; margin-bottom: 0"> <input type="text" name="Zip" size="20">Zip</p> <p style="margin-top: 0; margin-bottom: 0"> <input type="text" name="Type" size="20">Type</p> <p style="margin-top: 0; margin-bottom: 0"> <input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p> </form> </body> </html> <?php if(isset($_GET['go']){ mysql_connect('localhost', 'bob2_search', 'skater22') or die('Could not connect: ' . mysql_error()); $state=$_POST['State']; // u have to get the values from the form $zip=$_POST['Zip']; $type=$_POST['Type']; $query = ("SELECT * FROM real WHERE `State` LIKE '%$state%' && `zip` LIKE '%$zip%' && `Type` LIKE '%$type%'"); // * has to be a table name, so whatever state is $res = mysql_query($query); //misspelled query while($row=mysql_fetch_assoc($res)){ $state=$row['State']; $zip=$row['zip']; /////check all the array names for capitalization against ur db fields $type=$row['type']; $id=$row['custID']; echo '<table align="center" cellspacing="10" cellpadding="15"><tr><td align="left"><b>State</b></td><td align="left"><b>Zip</b></td><td align="left"><b>Type</b></td>'; echo "<tr><td align=\"left\">$id</td><td align=\"left\">$state</td><td align=\"left\">$zip</td><td align=\"left\">$type</td></tr>"; }//end while }//end go check Link to comment https://forums.phpfreaks.com/topic/164969-some-help/#findComment-870169 Share on other sites More sharing options...
bob2588 Posted July 7, 2009 Author Share Posted July 7, 2009 there is still on error like i said before i dont know why i am getting the error here is the error Parse error: syntax error, unexpected '{' in /home/bob2/public_html/Search/search.php on line 35 <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 1</title> </head> <body> <form method="POST" action="?go"> <p style="margin-top: 0; margin-bottom: 0"> </p> <p style="margin-top: 0; margin-bottom: 0"> <input type="text" name="State" size="20">State</p> <p style="margin-top: 0; margin-bottom: 0"> <input type="text" name="Zip" size="20">Zip</p> <p style="margin-top: 0; margin-bottom: 0"> <input type="text" name="Type" size="20">Type</p> <p style="margin-top: 0; margin-bottom: 0"> <input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p> </form> </body> </html> <?php if(isset($_GET['go']){ // This is line 35 mysql_connect('localhost', 'bob2_search', 'skater22') or die('Could not connect: ' . mysql_error()); $state=$_POST['State']; // u have to get the values from the form $zip=$_POST['Zip']; $type=$_POST['Type']; $query = ("SELECT bob2_search FROM real WHERE `State` LIKE '%$state%' && `zip` LIKE '%$zip%' && `Type` LIKE '%$type%'"); // * has to be a table name, so whatever state is $res = mysql_query($query); //misspelled query while($row=mysql_fetch_assoc($res)){ $state=$row['State']; $zip=$row['zip']; /////check all the array names for capitalization against ur db fields $type=$row['type']; $id=$row['custID']; echo '<table align="center" cellspacing="10" cellpadding="15"><tr><td align="left"><b>State</b></td><td align="left"><b>Zip</b></td><td align="left"><b>Type</b></td>'; echo "<tr><td align=\"left\">$id</td><td align=\"left\">$state</td><td align=\"left\">$zip</td><td align=\"left\">$type</td></tr>"; }//end while }//end go check Thank you for all the help Link to comment https://forums.phpfreaks.com/topic/164969-some-help/#findComment-870184 Share on other sites More sharing options...
seventheyejosh Posted July 7, 2009 Share Posted July 7, 2009 if(isset($_GET['go']){ BECOMES if(isset($_GET['go'])){ Link to comment https://forums.phpfreaks.com/topic/164969-some-help/#findComment-870191 Share on other sites More sharing options...
bob2588 Posted July 7, 2009 Author Share Posted July 7, 2009 Thnak you for all the help but this is the error i got when i tried wrint the script from a php tutorial The Error is Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/bob2/public_html/Search/search.php on line 46 <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 1</title> </head> <body> <form method="POST" action="?go"> <p style="margin-top: 0; margin-bottom: 0"> </p> <p style="margin-top: 0; margin-bottom: 0"> <input type="text" name="State" size="20">State</p> <p style="margin-top: 0; margin-bottom: 0"> <input type="text" name="Zip" size="20">Zip</p> <p style="margin-top: 0; margin-bottom: 0"> <input type="text" name="Type" size="20">Type</p> <p style="margin-top: 0; margin-bottom: 0"> <input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p> </form> </body> </html> <?php if(isset($_GET['go'])){ mysql_connect('localhost', 'bob2_search', 'skater22') or die('Could not connect: ' . mysql_error()); $state=$_POST['State']; // u have to get the values from the form $zip=$_POST['Zip']; $type=$_POST['Type']; $query = ("SELECT bob2_search FROM real WHERE `State` LIKE '%$state%' && `zip` LIKE '%$zip%' && `Type` LIKE '%$type%'"); // * has to be a table name, so whatever state is $res = mysql_query($query); //misspelled query while($row=mysql_fetch_assoc($res)){ // here is line 46 $state=$row['State']; $zip=$row['zip']; /////check all the array names for capitalization against ur db fields $type=$row['type']; $id=$row['custID']; echo '<table align="center" cellspacing="10" cellpadding="15"><tr><td align="left"><b>State</b></td><td align="left"><b>Zip</b></td><td align="left"><b>Type</b></td>'; echo "<tr><td align=\"left\">$id</td><td align=\"left\">$state</td><td align=\"left\">$zip</td><td align=\"left\">$type</td></tr>"; }//end while }//end go check Link to comment https://forums.phpfreaks.com/topic/164969-some-help/#findComment-870212 Share on other sites More sharing options...
seventheyejosh Posted July 7, 2009 Share Posted July 7, 2009 after the assigning.. where u do var=post['blah'] put echo "state - $state zip - $zip type - $type"; then, put those values in your query string and run it in the sql tab of your phpmyadmin Link to comment https://forums.phpfreaks.com/topic/164969-some-help/#findComment-870214 Share on other sites More sharing options...
bob2588 Posted July 7, 2009 Author Share Posted July 7, 2009 i have no idea what you are talking about :/ Link to comment https://forums.phpfreaks.com/topic/164969-some-help/#findComment-870393 Share on other sites More sharing options...
seventheyejosh Posted July 7, 2009 Share Posted July 7, 2009 you know php my admin? where u create your tables and fields etc? Link to comment https://forums.phpfreaks.com/topic/164969-some-help/#findComment-870398 Share on other sites More sharing options...
bob2588 Posted July 7, 2009 Author Share Posted July 7, 2009 yea Link to comment https://forums.phpfreaks.com/topic/164969-some-help/#findComment-870405 Share on other sites More sharing options...
seventheyejosh Posted July 7, 2009 Share Posted July 7, 2009 basically if you have something like this: $id=$_POST['id']; $text=$_POST['text']; $query="UPDATE `table` SET `text`='$text' WHERE `id`='$id'"; then you want to make sure that there is actually something in your variables. So you can either add one of these two lines to ensure that you're populating your query properly. $id=$_POST['id']; $text=$_POST['text']; ///either print_r($_POST); exit(); ////which will show the whole post array, a little confusing if you're new to arrays, but easiest ////or do echo "id - $id text - $text"; exit(); /////which will just show your variables. $query="UPDATE `table` SET `text`='$text' WHERE `id`='$id'"; so if you do either of these and nothing shows, then your form is prolly messed up, no action, wrong input names etc. if it works, then manually put the variables value into the sql string like so: if $text=sometext and $id=1, you'll do: UPDATE `table` SET `text`='sometext' WHERE `id`='1' then take that completed line and go to your DB management software, like phpmyadmin, and there should be either a tab or some item that'll let you run sql right there. When you put that line in and hit go, if it returns nothing, then your echoing of results isnt the problem, if however it returns some entries, then you have to figure out why you are getting no results in your code. the SQL tab is right at the top when you click a table name. its like BROWSE || STRUCTURE || SQL || OPERATIONS || ETC ETC Link to comment https://forums.phpfreaks.com/topic/164969-some-help/#findComment-870407 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.