probleem met script ajax live search / dreamweaver

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Willem van weesenbeek

willem van weesenbeek

06/11/2010 22:00:37
Quote Anchor link
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
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?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)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?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);
?>





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

[i]wat doe ik verkeerd.

ik kom er niet uit. ben nog niet zo erg ervaren als jullie met dit soort dingen.[/i]
Gewijzigd op 06/11/2010 22:49:58 door Willem van weesenbeek
 
PHP hulp

PHP hulp

24/04/2024 15:03:16
 
Victor Php

Victor Php

06/11/2010 22:08:40
Quote Anchor link
Post relevante code en zet die tussen [.code][/.code] tags (zonder de puntjes)
 
Willem van weesenbeek

willem van weesenbeek

06/11/2010 22:14:32
Quote Anchor link
had per ongelijk <code> gebruikt ipv
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
 
Noppes Homeland

Noppes Homeland

06/11/2010 22:45:56
Quote Anchor link
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.
 
Jordi Kroon

Jordi Kroon

06/11/2010 23:11:25
Quote Anchor link
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
 
- Ariën  -
Beheerder

- Ariën -

06/11/2010 23:23:55
Quote Anchor link
Op lijn 0???????
 
Willem van weesenbeek

willem van weesenbeek

06/11/2010 23:58:21
Quote Anchor link
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.

Toevoeging op 07/11/2010 00:06:33:

Heb het script van deze website geplukt.

omgebouwd zodat hij met db werkt

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



Toevoeging op 07/11/2010 00:19:52:

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

Toevoeging op 07/11/2010 00:24:01:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<? $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.
Gewijzigd op 07/11/2010 00:30:58 door willem van weesenbeek
 
- SanThe -

- SanThe -

07/11/2010 01:26:54
Quote Anchor link
Foutafhandeling inbouwen voor de query's dan krijg je de fout duidelijk op je scherm te zien. Nu is het gokken.
 
Willem van weesenbeek

willem van weesenbeek

07/11/2010 13:00:48
Quote Anchor link
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
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??
Gewijzigd op 07/11/2010 13:01:24 door willem van weesenbeek
 
Bas IJzelendoorn

Bas IJzelendoorn

07/11/2010 13:08:20
Quote Anchor link
- $result hoeft niet tussen quotes
- je opent geen <table>
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.