0

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'];
//}


}
?>
4
Contributors
19
Replies
70
Views
4 Years
Discussion Span
Last Post by bradly.spicer
0

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

0

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.

0

Just to be sure try this:

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

and see if you get an error message.

0

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

0

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

0

Okay, then the problem is in this part:

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

and not in your function.

0

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

0

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>
0

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

0

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.

Edited by Banderson

0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.