Jump to content

php mysql


ferellie

Recommended Posts

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..

<?php

include "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 database
mysql_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 div
if (mysql_num_rows($result)) {
while ($qry = mysql_fetch_array($result)) {
?>

<div id="business">

<?php
print "$qry[business]<br>";
?>
</div>

<div id="businessdescription">
Business description:</div>
<?php
print "$qry[description]<br>";
?>

<div id="contactname">
Contact person:</div>

<?php
print "$qry[name]<br>";
?>

<div id="location">
Location:</div>

<?php
print "$qry[town]";
?>
&nbsp;
<?php
print "$qry[postcode]<br>";
?>

<div id="telephone">
Telephone:</div>

<?php
print "$qry[phone]<br>";
?>

<div id="website">
<a href="

<?php
print "$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
Share on other sites

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
Share on other sites

[!--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
Share on other sites

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
Share on other sites

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.