Results 1 to 12 of 12
Thread: Formatting PHP Statments
-
03-05-2003, 07:36 AM #1Web Hosting Master
- Join Date
- Dec 2002
- Location
- UK
- Posts
- 838
Formatting PHP Statments
Hello all
just wondering if anyone can advise me on formatting PHP statements
i have the following piece of code which is part of a "Search" Facility
PHP Code:echo 'Product Details = <a href="'.$details[link].'">'.$details[prod_title].'<a/><br>';
echo "Product Description = `".$details["prod_description"]."'<br>";
echo "Availablitiy = `".$details["status"]."'<br>";
1) Put the Title In bold i.e Product Details, etc.. ive tried putting the <b></b> tags after the echo but it returns me errror
2) Put it all neatly in a table For example say a user searches for something and It finds more then one search results how wud i seperate each set of results from another using a table or Horizantal line even?
thanks
s
-
03-05-2003, 08:12 AM #2Web Hosting Master
- Join Date
- Jul 2002
- Location
- Missouri
- Posts
- 2,504
<?php // start
$q = mysql_query("SELECT link,prod_title,prod_description,status FROM <table> [clauses if apply...]");
$r = mysql_num_rows($q);
if (!$r)
echo('No results.');
else
{
?>
<table width="100%" cellpadding="3" cellspacing="1" border="0">
<?
while (list($link,$title,$desc,$status) = mysql_fetch_array($q))
{
?>
<tr>
<td align="left"><b>Product Details:</b></td>
<td align="left"><a href="<? echo($link) ?>"><? echo($title) ?></a></td>
</tr>
<tr>
<td align="left"><b>Product Description:</b></td>
<td align="left"><? echo($desc) ?></td>
</tr>
<tr>
<td align="left"><b>Availability</b>:</td>
<td align="left"><? echo($status) ?></td>
</tr>
<tr>
<td width="100%" colspan="2"><hr size="1" width="100%"></td>
</tr>
<?
}
?>
</table>
<?
}
// end ?>
Should work...What does one host say to the other? "(HostA) Want to go see a movie?" "(HostB) Sure, can your parents drive?"
I'm premium, and no, I did not have to pay $6 a month to figure that out.
-
03-05-2003, 11:35 AM #3Web Hosting Master
- Join Date
- Dec 2002
- Location
- UK
- Posts
- 838
hi there thanks for that it worked more or less kind of
What the problem im having is the $q function
basically it a search function seraching from a list box
i.e User enters some text in the text box..and can search from either "Product" or "Location"
the original Coding i had before was:
PHP Code:$q = "select * from prod_details where {$_POST['select']} like '%{$_POST['textfield']}%'";
"Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/virtual/site11/fst/var/www/html/SearchPage2.php on line 174
No results. "
Line 174 Being
$r = mysql_num_rows($q);
any ideas what wrong here?
here is the PHP code as below for the search..
PHP Code:
// Query the database with the information given
// start
$q = "select * from prod_details where {$_POST['select']} like '%{$_POST['textfield']}%'";
$r = mysql_num_rows($q);
if (!$r)
echo('No results.');
else
{
?>
<table width="100%" cellpadding="3" cellspacing="1" border="0">
<?
while (list($link,$title,$desc,$status,$category,$region,$comp_location) = mysql_fetch_array($q))
{
?>
<tr>
<td align="left"><font size="1"><b>Product Details:</b></font></td>
<td align="left"><font size="1"><a href="<? echo($link) ?>"><? echo($title) ?></a></font></td>
</tr>
<tr>
<td align="left"><font size="1"><b>Product Description:</b></font></td>
<td align="left"><font size="1"><? echo($desc) ?></font></td>
</tr>
<tr>
<td align="left"><font size="1"><b>Availability</b>:</font></td>
<td align="left"><font size="1"><? echo($status) ?></font></td>
</tr>
<tr>
<td align="left"><font size="1"><b>Competition Location:</b></font></td>
<td align="left"><font size="1"><? echo($comp_location) ?></a></font></td>
</tr>
<tr>
<td align="left"><font size="1"><b>Region:</b></font></td>
<td align="left"><font size="1"><? echo($region) ?></font></td>
</tr>
<tr>
<td align="left"><font size="1"><b>Category:</b></font></td>
<td align="left"><font size="1"><? echo($category) ?></font></td>
</tr>
<tr>
<td width="100%" colspan="2"><hr size="1" width="100%"></td>
</tr>
<?
}
?>
</table>
<font size="1">
<?
}
// end ?>
-
03-05-2003, 11:39 AM #4Web Hosting Master
- Join Date
- Jul 2002
- Location
- Missouri
- Posts
- 2,504
$q = mysql_query("select * from prod_details where ".$_POST['select']." like '%".$_POST['textfield']."%'");
Try that.What does one host say to the other? "(HostA) Want to go see a movie?" "(HostB) Sure, can your parents drive?"
I'm premium, and no, I did not have to pay $6 a month to figure that out.
-
03-05-2003, 11:42 AM #5Web Hosting Master
- Join Date
- Dec 2002
- Location
- UK
- Posts
- 838
hmm got this
Parse error: parse error in /home/virtual/site11/fst/var/www/html/SearchPage2.php on line 173
-
03-05-2003, 11:46 AM #6Web Hosting Master
- Join Date
- Dec 2002
- Location
- UK
- Posts
- 838
hmm actualyl hang on a min..i gotta recheck that
-
03-05-2003, 11:55 AM #7Web Hosting Master
- Join Date
- Dec 2002
- Location
- UK
- Posts
- 838
aha
thanks got it working
:-)
-
03-05-2003, 12:01 PM #8Web Hosting Master
- Join Date
- Jul 2002
- Location
- Missouri
- Posts
- 2,504
Great. Good luck.
P.S. How do you like list() vesus $blah['crap']? Just really got into using it myself after 2+ years in PHP / mySQL and I slapped myself for not using it before hand.
Long live list()What does one host say to the other? "(HostA) Want to go see a movie?" "(HostB) Sure, can your parents drive?"
I'm premium, and no, I did not have to pay $6 a month to figure that out.
-
03-05-2003, 12:02 PM #9Web Hosting Master
- Join Date
- Dec 2002
- Location
- UK
- Posts
- 838
Actualyl
something realyl weird is happening
the categories are not corresponding with the answer
for example ive got about 10 field in the database
when a user searched i wanted the following field to be displayed
Product Details:
Product Description:
Availability:
Competition Location:
Region:
Availability:
But when i do a search the following results come up
Product Details: Sony Walkman 2
Product Description: A Walkman that you can play a lot of music and everything else on and much more more thing just putting text in here for the sake ofit
Availability: http://www.sony.com
Competition Location: 2003-05-06
Region: 2003-02-04
Category: no
what it looks like its doing is picking up all the fields from the database
it seems it mixing it up
cos the fields i have in the database in order is:
Prod_details,prod_description,link,effective_from,effective_to,Availability,region,competition_location etcc
what the results is showing is going thru all the fields in the db..
how comes its doing that
-
03-05-2003, 12:05 PM #10Web Hosting Master
- Join Date
- Jul 2002
- Location
- Missouri
- Posts
- 2,504
It's because you're doing a SELECT * (* = everything) ... list() won't know which you want. list() expects every argument passed in to corrospond to the Nth arg-1 array pointer.
You need to change SELECT * to SELECT field1,field2,field3 and make sure they're in order of your list($var,$var2) = mysql_fetch_array(whatever)What does one host say to the other? "(HostA) Want to go see a movie?" "(HostB) Sure, can your parents drive?"
I'm premium, and no, I did not have to pay $6 a month to figure that out.
-
03-05-2003, 12:45 PM #11Web Hosting Master
- Join Date
- Dec 2002
- Location
- UK
- Posts
- 838
Thanks there!
got it working
it was a case of rearranging things
making the Query
$q = mysql_query("select link,prod_title,prod_description,status,comp_location,region,category from prod_details where ".$_POST['select']." like '%".$_POST['textfield']."%'");
compatible and matching with (list)
while (list($link,$title,$desc,$status,$comp_location,$region,$category) = mysql_fetch_array($q))
i must admit it took me a while to figure out that these 2 were somehow related to each other ..i just kept on modifying the query and putting things at random and guessing..until i realised my mistake
thanks anyhow much appreciated
regards
s
-
03-05-2003, 12:53 PM #12Web Hosting Master
- Join Date
- Jul 2002
- Location
- Missouri
- Posts
- 2,504
That's the downfall to useing list() in that it requires every arguement to match the array set (from mysql_fetch_array()) I should of pointed that out, so it's sorta my fault.
Anyways, good thing is that it works and that's all that counts.
Best of luck in the future.What does one host say to the other? "(HostA) Want to go see a movie?" "(HostB) Sure, can your parents drive?"
I'm premium, and no, I did not have to pay $6 a month to figure that out.