Go Back   Forum Care Forums > Development Reference Area > Php Development

Reply
 
LinkBack Thread Tools Display Modes
Attempting to search a MySQL database from PHP not working
Old
  (#1)
Jason Pruim
Guest
 
Posts: n/a
Default Attempting to search a MySQL database from PHP not working - 06-02-2007, 08:56 PM

Hi Everyone, I am attempting to setup a search field on a database
application I'm dinking around with and running into problems that
I'm hoping someone might be able to shed some light on.

Here is the code I am using to display the results of the search:

echo ('<table border="1">');
echo "<tr><th>First Name</th><th>Author</th><th>Pages</th></tr>";

$result_row[] = mysql_query($query) or die(mysql_error());
echo "Result_row dump: $result_row <BR>";
$num=mysql_numrows($result);
echo "Num dump: $num <BR>";
$i= 0;

while($i < $num) {
echo "<tr><td>";
echo $result_row[0] . '</td><td>';
echo $result_row[1] . '</td><td>';
echo $result_row[2] . '</td></tr>';
$i++;
}

echo ("</table>");


the problem is instead of printing out the actual results it prints
out 6 fields that say: "Resource id #5"

the query I'm using is: SELECT FName, LName, Add1, Add2 FROM current
WHERE FName like '%jason%' which works in MySQL

I can't find any errors in my log files to even give me a hint as to
what is going on.

If someone could take a look I would greatly appreciate it.

Jason Pruim
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: [PHP] Attempting to search a MySQL database from PHP not working
Old
  (#2)
Davi
Guest
 
Posts: n/a
Default Re: [PHP] Attempting to search a MySQL database from PHP not working - 06-02-2007, 08:56 PM

Em Quinta 31 Maio 2007 16:25, Jason Pruim escreveu:
> Hi Everyone, I am attempting to setup a search field on a database
> application I'm dinking around with and running into problems that
> I'm hoping someone might be able to shed some light on.
>
> Here is the code I am using to display the results of the search:
>
> echo ('<table border="1">');
> echo "<tr><th>First Name</th><th>Author</th><th>Pages</th></tr>";
>
> $result_row[] = mysql_query($query) or die(mysql_error());
> echo "Result_row dump: $result_row <BR>";
> $num=mysql_numrows($result);
> echo "Num dump: $num <BR>";
> $i= 0;
>

/*
> while($i < $num) {

*/

$result=$result_row[0];

while($result_row = mysql_fetch_array($result) {

> echo "<tr><td>";
> echo $result_row[0] . '</td><td>';
> echo $result_row[1] . '</td><td>';
> echo $result_row[2] . '</td></tr>';
> $i++;
> }
>
> echo ("</table>");
>
>
> the problem is instead of printing out the actual results it prints
> out 6 fields that say: "Resource id #5"
>
> the query I'm using is: SELECT FName, LName, Add1, Add2 FROM current
> WHERE FName like '%jason%' which works in MySQL
>
> I can't find any errors in my log files to even give me a hint as to
> what is going on.
>
> If someone could take a look I would greatly appreciate it.
>


HTH

--
Davi Vidal
EMAIL REMOVED
EMAIL REMOVED
--
"Religion, ideology, resources, land,
spite, love or "just because"...
No matter how pathetic the reason,
it's enough to start a war. "
--------------------------------------------------------
Por favor não faça top-posting, coloque a sua resposta abaixo desta linha.
Please don't do top-posting, put your reply below the following line.
--------------------------------------------------------

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBGXyGT33UYOg0uzToRAtZwAKDIVc5q2oCCE6Zsf0/COT6ze3jeZgCcDo6o
hy49qkFVYlDrI0a6+UDioYI=
=jlaS
-----END PGP SIGNATURE-----

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] Attempting to search a MySQL database from PHP notworking
Old
  (#3)
Robert Cummings
Guest
 
Posts: n/a
Default Re: [PHP] Attempting to search a MySQL database from PHP notworking - 06-02-2007, 08:56 PM

On Thu, 2007-05-31 at 15:25 -0400, Jason Pruim wrote:
> Hi Everyone, I am attempting to setup a search field on a database
> application I'm dinking around with and running into problems that
> I'm hoping someone might be able to shed some light on.
>
> Here is the code I am using to display the results of the search:
>
> echo ('<table border="1">');
> echo "<tr><th>First Name</th><th>Author</th><th>Pages</th></tr>";
>
> $result_row[] = mysql_query($query) or die(mysql_error());


mysql_query() doesn't return the rows. Go read the manual.

Cheers,
Rob.
--
..------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] Attempting to search a MySQL database from PHP not working
Old
  (#4)
Dave Goodchild
Guest
 
Posts: n/a
Default Re: [PHP] Attempting to search a MySQL database from PHP not working - 06-02-2007, 08:56 PM

Your problem is this:

>
> $result_row[] = mysql_query($query) or die(mysql_error());



....you are ***igning a query to a variable. What you need to do is
something like this:

$result = mysql_query($query) or die(mysql_error());
while ($result_row = mysql_fetch_array($result)) {
......
}

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] Attempting to search a MySQL database from PHP not working
Old
  (#5)
Jason Pruim
Guest
 
Posts: n/a
Default Re: [PHP] Attempting to search a MySQL database from PHP not working - 06-02-2007, 08:56 PM


On May 31, 2007, at 3:27 PM, Davi wrote:

> Em Quinta 31 Maio 2007 16:25, Jason Pruim escreveu:
>> Hi Everyone, I am attempting to setup a search field on a database
>> application I'm dinking around with and running into problems that
>> I'm hoping someone might be able to shed some light on.
>>
>> Here is the code I am using to display the results of the search:
>>
>> echo ('<table border="1">');
>> echo "<tr><th>First Name</th><th>Author</th><th>Pages</th></tr>";
>>
>> $result_row[] = mysql_query($query) or die(mysql_error());
>> echo "Result_row dump: $result_row <BR>";
>> $num=mysql_numrows($result);
>> echo "Num dump: $num <BR>";
>> $i= 0;
>>

> /*
>> while($i < $num) {

> */
>
> $result=$result_row[0];
>
> while($result_row = mysql_fetch_array($result) {


Worked perfectly after adding a closing ) Thanks for the tip!

>
>> echo "<tr><td>";
>> echo $result_row[0] . '</td><td>';
>> echo $result_row[1] . '</td><td>';
>> echo $result_row[2] . '</td></tr>';
>> $i++;
>> }
>>
>> echo ("</table>");
>>
>>
>> the problem is instead of printing out the actual results it prints
>> out 6 fields that say: "Resource id #5"
>>
>> the query I'm using is: SELECT FName, LName, Add1, Add2 FROM current
>> WHERE FName like '%jason%' which works in MySQL
>>
>> I can't find any errors in my log files to even give me a hint as to
>> what is going on.
>>
>> If someone could take a look I would greatly appreciate it.
>>

>
> HTH
>
> --
> Davi Vidal
> EMAIL REMOVED
> EMAIL REMOVED
> --
> "Religion, ideology, resources, land,
> spite, love or "just because"...
> No matter how pathetic the reason,
> it's enough to start a war. "
> --------------------------------------------------------
> Por favor não faça top-posting, coloque a sua resposta abaixo desta
> linha.
> Please don't do top-posting, put your reply below the following line.
> --------------------------------------------------------

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] Attempting to search a MySQL database from PHP not working
Old
  (#6)
Davi
Guest
 
Posts: n/a
Default Re: [PHP] Attempting to search a MySQL database from PHP not working - 06-02-2007, 08:56 PM

Em Quinta 31 Maio 2007 16:38, Jason Pruim escreveu:
> >
> > while($result_row = mysql_fetch_array($result) {

>
> Worked perfectly after adding a closing ) Thanks for the tip!
>


Forgive me for that!!! #'_'#
I *always* forget the closing )... =P


--
Davi Vidal
EMAIL REMOVED
EMAIL REMOVED
--
"Religion, ideology, resources, land,
spite, love or "just because"...
No matter how pathetic the reason,
it's enough to start a war. "
--------------------------------------------------------
Por favor não faça top-posting, coloque a sua resposta abaixo desta linha.
Please don't do top-posting, put your reply below the following line.
--------------------------------------------------------

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBGXybE33UYOg0uzToRAgZ9AKDRn/DzfnhptzepzB+Ft3t1jys2jQCgsi94
eCCqc1M4IkF/sLTABMPJBHc=
=eTxc
-----END PGP SIGNATURE-----

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] Attempting to search a MySQL database from PHP notworking
Old
  (#7)
Richard Lynch
Guest
 
Posts: n/a
Default Re: [PHP] Attempting to search a MySQL database from PHP notworking - 06-02-2007, 08:56 PM



On Thu, May 31, 2007 2:25 pm, Jason Pruim wrote:
> Hi Everyone, I am attempting to setup a search field on a database
> application I'm dinking around with and running into problems that
> I'm hoping someone might be able to shed some light on.
>
> Here is the code I am using to display the results of the search:
>
> echo ('<table border="1">');
> echo "<tr><th>First Name</th><th>Author</th><th>Pages</th></tr>";
>
> $result_row[] = mysql_query($query) or die(mysql_error());


I also have to wonder why you are building an array of query result
resources...

You probably could do this with just one SQL query and some order by
clauses to get what you want, without hitting the DB so much.

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




Contact Us - Forum Care Forums - Archive - Top