Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in

Good afternoon.

I’m already two days fighting with this script.
but he continues with this error.

Anyone have an idea what goes wrong?
this is the script.

[php]<?php
require_once(’_data/db.php’);
global $hostname_cms, $database_cms, $username_cms, $password_cms, $cms;

mysql_select_db($database_cms, $cms); 
$query_bestelling = "SELECT * FROM bestelling WHERE idbedrijf='2593at142' ORDER BY prijs"; 
$bestelling = mysql_query($query_bestelling, $cms) or die(mysql_error()); 
$row_bestelling = mysql_fetch_assoc($bestelling); 
$totalRows_bestelling = mysql_num_rows($bestelling); 

$groups = Array(); 
    while($w = mysql_fetch_assoc($query_bestelling)) { 
          if(!isset($groups[$w['tafel']])) $groups[$w['tafel']] = Array(); 
  $groups[$w['tafel']][] = $w; 

}

foreach($groups as $group_name => $sections) {

echo " <div id="".$row_bestelling[‘tafel’]."" class=“popup_block”>\n";
echo " <table width=“100%” border=“0” cellspacing=“2” cellpadding=“2”>\n";

foreach($sections as $section) { 

echo "

<td align=“left” valign=“middle” height=“25” width=“100%”>".$row_bestelling[‘product’]."\n";

}

echo " \n";
echo " \n";

}

echo " <a href="#?w=700" rel="".$row_bestelling[‘tafel’]."" class=“poplight”>\n";
echo " <div class=“myButton”.$row_bestelling[‘order’]."">\n";
echo " <table width=“170” height=“170” border=“0” cellspacing=“2” cellpadding=“2”>\n";
echo "

\n";
echo " <td align=“center” valign=“middle”>".$row_bestelling[‘tafel’]."\n";
echo " \n";
echo " \n";
echo " \n";
echo " \n";

mysql_free_result($bestelling);
?>[/php]

What information is stored in the $cms variables. Is it a connection to the sql database???

Best Tanzeelniazi,

This is the file db.php

[php]$hostname_cms = “localhost”;
$database_cms = “data_local”;
$username_cms = “data_local”;
$password_cms = “local”;
$cms = mysql_pconnect($hostname_cms, $username_cms, $password_cms) or trigger_error(mysql_error(),E_USER_ERROR);[/php]

Thanks a lot

well I think your error is here:
[php] while($w = mysql_fetch_assoc($query_bestelling)) { [/php]

Your are trying to fetch a string not a mysql result set. The line should be as follows
[php] while($w = mysql_fetch_assoc($bestelling)) { [/php]

Hope this solves the problem

Hello,

I believe the error is in your while loop syntax.

The variable used for your mysql_fetch_assoc() is $query_bestelling which is your query string. You should be using $bestelling.

[php] while($w = mysql_fetch_assoc($bestelling)) {
if(!isset($groups[$w[‘tafel’]])) $groups[$w[‘tafel’]] = Array();
$groups[$w[‘tafel’]][] = $w;
} [/php]

@tanzeelniazi

I guess I shouldn’t pee while I’m answering if I want to be first…

hahahah… very well said valandor062 but it’s not important who gets the first position, if we solve someone’s problem. 8)

The thing that matters most is at least you spared the time to read someone’s code ;D

thank you all.
the problem is solved.

the script do’nt make groups anymore. he show only one group, while there are multiple groups.
it should look like this.

2012-05-03

1 Take dog for walk
2 Park
3 Go out for dinner
4 Little Italian Restaurant

2012-05-04

1 Get Car Serviced
2 Johns Auto and Mechanical

2012-05-05

1 Do Grocery Shopping
2 Fresh Supermarket
3 Go See Movie
4 MegaPlex Cinemas
5 Meet Up With Sam
6 Hole In The Wall Bar

the script should make category

hope you can help me

When i do like the script below than he makes the groups but he do’nt show the first row or id

[php]

<?php require_once('db.php'); global $section, $hostname_cms, $database_cms, $username_cms, $password_cms, $cms; mysql_select_db($database_cms, $cms); mysql_select_db($database_cms, $cms); $query_bestelling = "SELECT * FROM bestelling WHERE idbedrijf='2593at142' ORDER BY prijs"; $bestelling = mysql_query($query_bestelling, $cms) or die(mysql_error()); $row_bestelling = mysql_fetch_assoc($bestelling); $totalRows_bestelling = mysql_num_rows($bestelling); $groups = Array(); while($w = mysql_fetch_assoc($bestelling)) { if(!isset($groups[$w['tafel']])) $groups[$w['tafel']] = Array(); $groups[$w['tafel']][] = $w; } foreach($groups as $group_name => $sections) { echo "\n"; echo "
\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " TAFEL\n"; echo " $group_name\n"; echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; echo "\n"; foreach($sections as $section) { echo " \n"; } echo "
".$section['product']."
\n"; echo "
\n"; } ?>[/php]

Well this is on top of my head. ???

It would be nice if you explain what you want to accomplish and the database structure.

Sorry.

all ids fall under a specific group.
for example.
all ids with the number 500 falls under one group.
all ids with the number 501 is again under a different group.
and so on

the name of the group is, for example, 500 and if you click on 500 he shows all rows that belong to this group.
i put a attachment in to this message.

Thanks and i hope it is understandable


example.jpg

OK, You have grouped your products by numbers and when someone click on 500 it should display all the products??? AM I RIGHT???

Yes you’re right ;D

Well than where is

[php]$query_bestelling = “SELECT * FROM bestelling WHERE idbedrijf=‘2593at142’ ORDER BY prijs”; [/php]

idbedrif etc.??? because in the picture shown above there is no such column?

Sponsor our Newsletter | Privacy Policy | Terms of Service