If got a problem in a mysql select string. I get some data from a mysql table and want use some data to pull data from another table. When I use static (i typed it in) it works good but when i use the data that i got from the mysql database it returns nothing. When i "echo" the select string it shows me the good string. Can someone help me? Sorry if its a stupid question i'am just a starter.
Thanx a lot
Rob

<?PHP
   $naam1 = trim($naam);
   werknemers($naam1);
function werknemers($test)
{

 $select_query_werknemers = "SELECT * FROM `werknemers` WHERE Domeinnaam = '$test'";
 $resultwerknemers = mysql_query($select_query_werknemers);

 if ($resultwerknemers) {
  echo $select_query_werknemers; //shows the right string: SELECT * FROM `werknemers` WHERE Domeinnaam = '...'
  $rowwerknemers = mysql_fetch_row($resultwerknemers); 
  print_r($rowwerknemers); //Shows nothing
  $volledigenaam = $rowwerknemers[1]; 
 echo $volledigenaam; //shows nothing
 return $volledigenaam;
 }
 else {   
  $volledigenaam = "Niet  gevonden";
 }

//while ( $rowwerknemers = mysql_fetch_row($resultwerknemers)){
//  echo $rowwerknemers['Volledige Naam'];
//}


}
?>

Recommended Answers

All 19 Replies

resultwerknemers will be true even if no records are returned. Are you sure you tested with a parameter that actually exists in the table?

Hi Pritaeas, i did test it with an existing parameter in the table. When i copy the returned echo string in phpmyadmin as a sql query it comes with a record. by the way thanx for your time helping me out with this.

Just to be sure try this:

$resultwerknemers = mysql_query($select_query_werknemers) or die(mysql_error());

and see if you get an error message.

I didn't get a error message when i add it. When i echo $resultwerknemers it comes with a resource id #

What outputs this:

print_r(mysql_num_rows($resultwerknemers));

It comes with 0. I don't get it were am i going wrong?

Are you sure that you are using the correct server/database?

Iám not sure of anything right now:) When i echo:

select_query_werknemers = "SELECT * FROM `werknemers` WHERE Domeinnaam = '$test'"; 

it returns for example:

SELECT * FROM `werknemers` WHERE Domeinnaam = 'username'

when i copy paste it in phpmyadmin in the sql query it works.

when i add it in my script is also working

$select_query_werknemers = "SELECT * FROM `werknemers` WHERE Domeinnaam = 'username'";

regards

Rob

Okay, then the problem is in this part:

$naam1 = trim($naam);
werknemers($naam1);

and not in your function.

Strange this gives the right output: username. But when i give it the manualy a value it is working. The value of $naam is goming out of the same database only an other table. Is there something i missed?

regards

See where the name is coming from, and if it is assigned correctly.

This the whole script. I can't find any problems. Maybe blind for it

<HTML>
<Head>

</head>
<?PHP

$select_query_citrix = sprintf("SELECT * FROM citrix"); 
$resultcitrix = mysql_query($select_query_citrix); 
echo "<table width='1500' border='1' cellpadding='0' cellspacing='0' bordercolor='#CCCCCC'>"; 
echo "<tr><td width = '25%'><t1>Naam</td>", "<td><t1>Werkstation</td>", "<td><t1>Aanmeldtijd</td>", "<td><t1>Citrix Status</td>", "<td><t1>Telefoonnummer</td></tr>";
echo "</table>";
echo "<br>";

$naam = "Test";
$counter = 0;

if ($resultcitrix) {   
 while ($rowcitrix = mysql_fetch_array($resultcitrix)){ 

  if ($naam <> $rowcitrix['Domein Naam']){
  echo "<table>";
   $naam     = $rowcitrix['Domein Naam']; 
   $werkstation = $rowcitrix['Werkstation'];
   $Aanmeldtijd = $rowcitrix['Aanmeldtijd'];
   $Status  = $rowcitrix['Status'];
   //require  "./scripts/querywerkplek.php";
   //require "./scripts/querywerknemers.php";


   $naam1 = trim($naam);
   werknemers($naam1);

$counter++;
$bgcolor = ($counter % 2 === 0) ?   '#EEEEEE' : '#FFFFEC';

   //echo werknemers($volledigenaam);
   //echo "<td bgcolor=$bgcolor>",$volledigenaam,"</td>";
   echo "<td bgcolor=$bgcolor>",$naam,"</td>"; 
   echo "<td bgcolor=$bgcolor>",$werkstation,"</td>";
   echo "<td bgcolor=$bgcolor>",$Aanmeldtijd,"</td>";
   echo "<td bgcolor=$bgcolor>",$Status,"</td>";
   echo "<td bgcolor=$bgcolor>",$telefoonnummer,"</td>";
echo "</table>";

  } 
 }
}
else {   
 handle_error("there was a problem finding your information in our system.",                
 "Error locating user with ID"); 
} 

function werknemers($test)
{

 $select_query_werknemers = "SELECT * FROM `werknemers` WHERE Domeinnaam = '$test'";
 $resultwerknemers = mysql_query($select_query_werknemers) or die(mysql_error());

 if ($resultwerknemers) {
  echo $select_query_werknemers;  
  $rowwerknemers = mysql_fetch_row($resultwerknemers); 
  print_r($rowwerknemers);
  $volledigenaam = $rowwerknemers[1]; 
 echo $volledigenaam;
 return $volledigenaam;
 }
 else {   
  $volledigenaam = "Niet  gevonden";
 }


}


?>
</HTML>

You are using Domein naam, is there really a space in this column name?

Yes it is and its returning the correct output

Am out of ideas. I suggest you do some debugging. Follow the code step by step.

Thanx for your help. i allready followed it step by step. I don't see it anymore. Perhaps let it be for a will.

What is your database name? Where are you selecting it? Are you connecting and selecting in another include?
If this is your complete code above, then the query is failing. Add die() like so on this line.

$resultcitrix = mysql_query($select_query_citrix)or die(mysql_error()); 

You will need to connect and select above this line.

Found the problem. The data in the Mysql table was corrupt. I read new data in the tables and it worked.

Everyone thanx for your time and help

Robon please click solve at the bottom of the thread.

And in future don't use spaces in a DB. Use "_" for example

The Column
The_Column

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.