ferellie Posted March 3, 2006 Share Posted March 3, 2006 I am using table with several fields which I display in a div no problem. I need to display all fields on a seperate page where the categories field contains the string web as an example. This is my code..<?phpinclude "config.php";// connect to the mysql server$link = mysql_connect($server, $db_user, $db_pass)or die ("Could not connect to mysql because ".mysql_error());// select the databasemysql_select_db($database)or die ("Could not select database because ".mysql_error());// read data from database$result = mysql_query("select * from $table WHERE categories LIKE %web% order by id desc limit $rows", $link)or die ("Could not read data because ".mysql_error());?>AND TO DISPLAY IN A DIV<?php// print the data in a divif (mysql_num_rows($result)) {while ($qry = mysql_fetch_array($result)) {?><div id="business"><?phpprint "$qry[business]<br>";?></div><div id="businessdescription">Business description:</div><?phpprint "$qry[description]<br>";?><div id="contactname">Contact person:</div><?phpprint "$qry[name]<br>";?><div id="location">Location:</div><?phpprint "$qry[town]";?> <?phpprint "$qry[postcode]<br>";?><div id="telephone">Telephone:</div><?phpprint "$qry[phone]<br>";?><div id="website"><a href="<?phpprint "$qry[website]";?>">Visit Company Website</a></div><div id="endseperator"></div><?php}}mysql_close();?>MY CONFIG.PHP CONTENTS IS<?php$server = "localhost"; // server to connect to.$database = "pages"; // the name of the database.$db_user = "pages"; // mysql username to access the database with.$db_pass = "pass"; // mysql password to access the database with.$table = "denb"; // database table$rows = 500; // the number of table rows to display?>I would really appreciate any help,Thank you. Link to comment https://forums.phpfreaks.com/topic/3995-php-mysql/ Share on other sites More sharing options...
craygo Posted March 3, 2006 Share Posted March 3, 2006 since web is a string you have to encase it in quotes[code]$result = mysql_query("select * from $table WHERE categories LIKE '%web%' order by id desc limit $rows", $link)or die ("Could not read data because ".mysql_error());[/code]Ray Link to comment https://forums.phpfreaks.com/topic/3995-php-mysql/#findComment-13904 Share on other sites More sharing options...
ferellie Posted March 3, 2006 Author Share Posted March 3, 2006 [!--quoteo(post=351329:date=Mar 3 2006, 02:06 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Mar 3 2006, 02:06 PM) [snapback]351329[/snapback][/div][div class=\'quotemain\'][!--quotec--]since web is a string you have to encase it in quotes[code]$result = mysql_query("select * from $table WHERE categories LIKE '%web%' order by id desc limit $rows", $link)or die ("Could not read data because ".mysql_error());[/code]Ray[/quote][!--quoteo(post=351329:date=Mar 3 2006, 02:06 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Mar 3 2006, 02:06 PM) [snapback]351329[/snapback][/div][div class=\'quotemain\'][!--quotec--]since web is a string you have to encase it in quotes[code]$result = mysql_query("select * from $table WHERE categories LIKE '%web%' order by id desc limit $rows", $link)or die ("Could not read data because ".mysql_error());[/code]Ray[/quote]thank you but how do I get the text from the input box to replace the text 'web' in my code?Thanks Link to comment https://forums.phpfreaks.com/topic/3995-php-mysql/#findComment-13907 Share on other sites More sharing options...
craygo Posted March 3, 2006 Share Posted March 3, 2006 If I am understanding you correctly. you have a search field that user fill in and when they select it you want to use that as your filter?!?!if it is then use this[code]$web = $_POST['web'];$result = mysql_query("select * from $table WHERE categories LIKE "%$web%" order by id desc limit $rows", $link)or die ("Could not read data because ".mysql_error());[/code]If you only have specefic catagories I would suggest making the catagories form field a pulldown menu so people will get the right info. Then instead of using LIKE you can use "="Ray Link to comment https://forums.phpfreaks.com/topic/3995-php-mysql/#findComment-13964 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.