Re: [PHP-DB] A while loop prob ?

2002-02-14 Thread Jim Lucas [php]

Try this

if ($submit)
{
if($search == )
{
$error1 = font color=redNo Records found. Please use at least 1
character in search box/font;
} else {
$srchsql = select * from $tbn where name like \%$search%\ ;
$srchresult = mysql_query($srchsql, $con);
$name =$srchrow['name'];
$details =$srchrow['details'];
$price =$srchrow['price'];
$imgloc =$srchrow['imgloc'];
while (list($name, $details, $price, $imgloc) =
mysql_fetch_array($srchresult))
{
$display_srch_rows .=
trtd$imgloc/tdtd$name/tdtd$details/tdtd$price/td/tr;
}
echo $display_srch_rows;
}
}

the problem is, you were overwriting your results each time you went into
the loop therefor always ending up with the last returned result set.
if you use  .=  instead of  =  you will concat the results, therefor
making one long string.

then echo/print the $display_srch_rows variable.

Jim Lucas
- Original Message -
From: Dave Carrera [EMAIL PROTECTED]
To: php List [EMAIL PROTECTED]
Sent: Wednesday, February 13, 2002 11:40 AM
Subject: [PHP-DB] A while loop prob ?


 Hi All

 What have I done wrong here.

 3 yes 3 hours I have been plaing with this loop.

 All it shows is the last record in my db.

 It should show and record containing any string in the search.

 Error works

 Please help I beg you...

 As always thank you for any help

 Dave C

 - My Code Starts Here 

 if ($submit){
 if($search == ){
 $error1 = font color=redNo Records found. Please use at least
 1 character in search box/font;
 }
 else
 {
 $srchsql = select * from $tbn where name like \%$search%\ ;
 $srchresult = mysql_query($srchsql, $con);
 $name =$srchrow['name'];
 $details =$srchrow['details'];
 $price =$srchrow['price'];
 $imgloc =$srchrow['imgloc'];
 while (list($name, $details, $price, $imgloc)
 =mysql_fetch_array($srchresult)){

 $display_srch_rows =
 trtd$imgloc/tdtd$name/tdtd$details/tdtd$price/td/tr
 ;
 }
 }
 }

 Dave Carrera
 Website Designer
 http://www.davecarrera.com




 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] A while loop prob ?

2002-02-13 Thread Dave Carrera

Hi All

What have I done wrong here.

3 yes 3 hours I have been plaing with this loop.

All it shows is the last record in my db.

It should show and record containing any string in the search.

Error works

Please help I beg you...

As always thank you for any help

Dave C

- My Code Starts Here 

if ($submit){
if($search == ){
$error1 = font color=redNo Records found. Please use at least
1 character in search box/font;
}
else
{
$srchsql = select * from $tbn where name like \%$search%\ ;
$srchresult = mysql_query($srchsql, $con);
$name =$srchrow['name'];
$details =$srchrow['details'];
$price =$srchrow['price'];
$imgloc =$srchrow['imgloc'];
while (list($name, $details, $price, $imgloc)
=mysql_fetch_array($srchresult)){

$display_srch_rows =
trtd$imgloc/tdtd$name/tdtd$details/tdtd$price/td/tr
;
}
}
}

Dave Carrera
Website Designer
http://www.davecarrera.com
 



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] A while loop prob ?

2002-02-13 Thread William Fong

You forgot the:
- My Code Ends Here 

...


Jokes aside, and with some level of assumption, use:
if ( isset($submit) ){

Your while() should be:
while (list($name, $details, $price,
$imgloc)==mysql_fetch_array($srchresult)){


= - is to set a variable
== - is to compare two things


Not sure why you are hitting the Error.  Maybe its my inexperience.

HTH

-w



--
William Fong - [EMAIL PROTECTED]
Phone: 626.968.6424 x210  |  Fax: 626.968.6877
Wireless #: 805.490.7732|  Wireless E-mail: [EMAIL PROTECTED]




- Original Message -
From: Dave Carrera [EMAIL PROTECTED]
To: php List [EMAIL PROTECTED]
Sent: Wednesday, February 13, 2002 11:40 AM
Subject: [PHP-DB] A while loop prob ?


: Hi All
:
: What have I done wrong here.
:
: 3 yes 3 hours I have been plaing with this loop.
:
: All it shows is the last record in my db.
:
: It should show and record containing any string in the search.
:
: Error works
:
: Please help I beg you...
:
: As always thank you for any help
:
: Dave C
:
: - My Code Starts Here 
:
: if ($submit){
: if($search == ){
: $error1 = font color=redNo Records found. Please use at least
: 1 character in search box/font;
: }
: else
: {
: $srchsql = select * from $tbn where name like \%$search%\ ;
: $srchresult = mysql_query($srchsql, $con);
: $name =$srchrow['name'];
: $details =$srchrow['details'];
: $price =$srchrow['price'];
: $imgloc =$srchrow['imgloc'];
: while (list($name, $details, $price, $imgloc)
: =mysql_fetch_array($srchresult)){
:
: $display_srch_rows =
: trtd$imgloc/tdtd$name/tdtd$details/tdtd$price/td/tr
: ;
: }
: }
: }
:
: Dave Carrera
: Website Designer
: http://www.davecarrera.com
:
:
:
:
: --
: PHP Database Mailing List (http://www.php.net/)
: To unsubscribe, visit: http://www.php.net/unsub.php
:
:



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] A while loop prob ?

2002-02-13 Thread Rick Emery

Need to show us more code.

For instance: where is $srchrow set?

Next, change:
if ($submit){

to:
if (ISSET($submit)) {

Why are you over-writing $name, $details, $price, $imgloc with list() before
you even use them?


-Original Message-
From: Dave Carrera [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 13, 2002 1:40 PM
To: php List
Subject: [PHP-DB] A while loop prob ?


Hi All

What have I done wrong here.

3 yes 3 hours I have been plaing with this loop.

All it shows is the last record in my db.

It should show and record containing any string in the search.

Error works

Please help I beg you...

As always thank you for any help

Dave C

- My Code Starts Here 

if ($submit){
if($search == ){
$error1 = font color=redNo Records found. Please use at least
1 character in search box/font;
}
else
{
$srchsql = select * from $tbn where name like \%$search%\ ;
$srchresult = mysql_query($srchsql, $con);
$name =$srchrow['name'];
$details =$srchrow['details'];
$price =$srchrow['price'];
$imgloc =$srchrow['imgloc'];
while (list($name, $details, $price,
$imgloc)=mysql_fetch_array($srchresult)){

$display_srch_rows =
trtd$imgloc/tdtd$name/tdtd$details/tdtd$price/td/tr
;
}
}
}

Dave Carrera
Website Designer
http://www.davecarrera.com
 



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] A while loop prob ?

2002-02-13 Thread William Fong

Heh, with the help from Mr. Emery, I see the/a part of the problem now.  You
have to fetch the results before you can extract the data into variables.
After you do the query, you must run a/the mysql_fetch_array.

HTH

-w


--
William Fong - [EMAIL PROTECTED]
Phone: 626.968.6424 x210  |  Fax: 626.968.6877
Wireless #: 805.490.7732|  Wireless E-mail: [EMAIL PROTECTED]




- Original Message -
From: Dave Carrera [EMAIL PROTECTED]
To: php List [EMAIL PROTECTED]
Sent: Wednesday, February 13, 2002 11:40 AM
Subject: [PHP-DB] A while loop prob ?


: Hi All
:
: What have I done wrong here.
:
: 3 yes 3 hours I have been plaing with this loop.
:
: All it shows is the last record in my db.
:
: It should show and record containing any string in the search.
:
: Error works
:
: Please help I beg you...
:
: As always thank you for any help
:
: Dave C
:
: - My Code Starts Here 
:
: if ($submit){
: if($search == ){
: $error1 = font color=redNo Records found. Please use at least
: 1 character in search box/font;
: }
: else
: {
: $srchsql = select * from $tbn where name like \%$search%\ ;
: $srchresult = mysql_query($srchsql, $con);
: $name =$srchrow['name'];
: $details =$srchrow['details'];
: $price =$srchrow['price'];
: $imgloc =$srchrow['imgloc'];
: while (list($name, $details, $price, $imgloc)
: =mysql_fetch_array($srchresult)){
:
: $display_srch_rows =
: trtd$imgloc/tdtd$name/tdtd$details/tdtd$price/td/tr
: ;
: }
: }
: }
:
: Dave Carrera
: Website Designer
: http://www.davecarrera.com
:
:
:
:
: --
: PHP Database Mailing List (http://www.php.net/)
: To unsubscribe, visit: http://www.php.net/unsub.php
:
:



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php