ik ben bezig met een website wat met koken te maken heeft.
Het is de bedoeling dat gasten kunnen zoeken op productnaam en de resultaten zullen dan laten zien met welke andere producten het gecombineerd kan worden.

ik heb ajax live search optie.
maak gebruik van database. connectie is gerealiseerd door dreamweaver. (vind ik makkelijk om mee te werken ik weet dat hier de meningen over verdeeld zijn)

als ik de zoekfunctie gebruik krijg ik een foutmelding zie

http://www.kookfreaks.nl/foodpairing/pairing.php

Pairing.php

<?php virtual('/Connections/website.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_website, $website);
$query_itemspairing = "SELECT Naam FROM pairing ORDER BY Naam ASC";
$itemspairing = mysql_query($query_itemspairing, $website) or die(mysql_error());
$row_itemspairing = mysql_fetch_assoc($itemspairing);
$totalRows_itemspairing = mysql_num_rows($itemspairing);
?>
<html>
<head>
<script type="text/javascript">
function showUser(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","foodpairing.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<form>
<select name="Producten" id="Producten" onChange="showUser(this.value)">
  <?php
do {  
?>
  <option value="<?php echo $row_itemspairing['Naam']?>"<?php if (!(strcmp($row_itemspairing['Naam'], $row_itemspairing['Naam']))) {echo "selected=\"selected\"";} ?>><?php echo $row_itemspairing['Naam']?></option>
  <?php
} while ($row_itemspairing = mysql_fetch_assoc($itemspairing));
  $rows = mysql_num_rows($itemspairing);
  if($rows > 0) {
      mysql_data_seek($itemspairing, 0);
	  $row_itemspairing = mysql_fetch_assoc($itemspairing);
  }
?>
</select>
</form>
<br />
<div id="txtHint"><b>Resultaten worden hier weer gegeven.</b></div>

</body>
</html>
<?php
mysql_free_result($itemspairing);
?>



foodpairing.php

[code]

<?php virtual('/Connections/website.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysql_select_db($database_website, $website);
$query_zoeken = "SELECT * FROM pairing ORDER BY id ASC";
$zoeken = mysql_query($query_zoeken, $website) or die(mysql_error());
$row_zoeken = mysql_fetch_assoc($zoeken);
$totalRows_zoeken = mysql_num_rows($zoeken);mysql_select_db($database_website, $website);
$query_zoeken = "SELECT Naam FROM pairing ORDER BY Naam ASC";
$zoeken = mysql_query($query_zoeken, $website) or die(mysql_error());
$row_zoeken = mysql_fetch_assoc($zoeken);
$totalRows_zoeken = mysql_num_rows($zoeken);

echo "<table border='1'>
<tr>
<th>product:</th>
<th>kruiden:</th>
<th>fruitsoorten:</th>
<th>zuivel producten:</th>
<th>vlees soorten:</th>
<th>vis soorten:</th>
<th>Overige:<th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td width=200>" . $row['Naam'] . "</td>";
echo "<td width=200>" . $row['Kruiden'] . "</td>";
echo "<td width=200>" . $row['Fruit'] . "</td>";
echo "<td width=200>" . $row['Zuivel '] . "</td>";
echo "<td width=200>" . $row['Vlees'] . "</td>";
echo "<td width=200>" . $row['Vis'] . "</td>";
echo "<td width=200>" . $row['Overig'] . "</td>";
echo "</tr>";
}
echo "</table>";



mysql_free_result($zoeken);
?>

[code]


result:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/id438/domains/kookfreaks.nl/public_html/foodpairing/foodpairing.php on line 0

wat doe ik verkeerd.

ik kom er niet uit. ben nog niet zo erg ervaren als jullie met dit soort dingen.
Post relevante code en zet die tussen [.code][/.code] tags (zonder de puntjes)
Lekker handig hoor, je weet wel een lap aan dubbelzinnige niet relevante code te posten maar blijkbaar is het te moeilijk om ook de foutmelding erbij te posten.
foutmelding;

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/id438/domains/kookfreaks.nl/public_html/foodpairing/foodpairing.php on line 0

Op lijn 0???????
dat vond ik ook erg vaag ja.

als het zoekformulier word verstuurd worden de resultaten in een div weergegeven.

ik gebruik zoals gewoonlijk 2 bestanden die met elkaar werken.

volgens mij doet dreamweaver iets verkeerd. op lijn 0 kan deze melding toch niet voorkomen erg vaag verhaal.

[size=xsmall]Toevoeging op 07/11/2010 00:06:33:[/size]

Heb het script van deze website geplukt.

omgebouwd zodat hij met db werkt

http://www.w3schools.com/php/php_ajax_database.asp



[size=xsmall]Toevoeging op 07/11/2010 00:19:52:[/size]

misschien zit de fout hierin

while($row = mysql_fetch_array($result))

verwijst naar
$result

$result = mysql_query($sql);
verwijst naar $sql

$sql="SELECT * FROM user WHERE id = '".$q."'";

zal misschien de fout zitten

normaal zal dit werken maar nu niet

[size=xsmall]Toevoeging op 07/11/2010 00:24:01:[/size]


<? $q=$_GET["q"];

$con = mysql_connect('localhost', 'id43**', 'ef***');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("pairing", $con);

$sql="SELECT * FROM user WHERE id = '".$q."'";

$result = mysql_query($sql);

echo "<table border='1' width=80%>
<tr width= '95%' align='center'>
<th width= 200>product:</th>
<th width= 200>kruiden:</th>
<th width= 200>fruitsoorten:</th>
<th width= 200>zuivelsoorten:</th>
<th width= 200>vleessoorten:</th>
<th width= 200>vissoorten:</th>
<th width= 200>Overige:<th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr width= '95%' align='center'>";
  echo "<td width=200>" . $row['Naam'] . "</td>";
  echo "<td width=200>" . $row['Kruiden'] . "</td>";
  echo "<td width=200>" . $row['Fruit'] . "</td>";
  echo "<td width=200>" . $row['Zuivel '] . "</td>";
  echo "<td width=200>" . $row['Vlees'] . "</td>";
  echo "<td width=200>" . $row['Vis'] . "</td>";
  echo "<td width=200>" . $row['Overig'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

?>


nieuwe code aangepast maar werkt nog niet krijg foutmelding

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/id438/domains/kookfreaks.nl/public_html/foodpairing/foodpairing.php on line 26

deze verwijst naar while($row = mysql_fetch_array($result)) hierboven.

Foutafhandeling inbouwen voor de query's dan krijg je de fout duidelijk op je scherm te zien. Nu is het gokken.
while($row = mysql_fetch_array('$result'))
  {
  echo "<tr>";
  echo "<td width=200>" .$row['Naam']. "</td>";
  echo "<td width=200>" .$row['Kruiden']. "</td>";
  echo "<td width=200>" .$row['Fruit']. "</td>";
  echo "<td width=200>" .$row['Zuivel']. "</td>";
  echo "<td width=200>" .$row['Vlees']. "</td>";
  echo "<td width=200>" .$row['Vis']. "</td>";
  echo "<td width=200>" .$row['Overig']."</td>";
  echo "</tr>";
  echo "</table>";
  }

wat is hier fout aan??
- $result hoeft niet tussen quotes
- je opent geen <table>

Reageren