Jump to content

Resource ID#7


loxy1914

Recommended Posts

Hi everybody.

 

I have 3 years to deal with PHP, and I am facing an issue in this function:

 

 

  function searchByName($carTitle) {
  	$searchQuery = mysql_query("SELECT * FROM car WHERE `title`= '$carTitle'") 
			   or die(mysql_error()) ;
echo $searchQuery;
while($results = mysql_fetch_assoc($searchQuery)){
  print($results['title']);
}}

 

I am trying to print the executing query,also.

 

Can someone help me with this?

Link to comment
https://forums.phpfreaks.com/topic/251576-resource-id7/
Share on other sites

I hope this helps.

 

<?php
function searchByName($carTitle) {
    $query = "SELECT * FROM car WHERE `title`= '$carTitle'";
    $searchQuery = mysql_query($query) 
              or die(mysql_error()) ;
    echo $query;
    while($results = mysql_fetch_assoc($searchQuery)){
        print($results['title']);
    }}
?>

Link to comment
https://forums.phpfreaks.com/topic/251576-resource-id7/#findComment-1290195
Share on other sites

That`s true.

 

I have decided to return and call it in another script.

 

Should I avoid something,like this?

 

It's ok to use a return. But in your case you will only return the first value from the database not the whole result set from the query.

 

http://php.net/manual/en/function.return.php

Link to comment
https://forums.phpfreaks.com/topic/251576-resource-id7/#findComment-1290209
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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