[SOLVED] Repeat Region DWMX Problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

saltriver
Forum Commoner
Posts: 59
Joined: Fri Mar 12, 2004 2:40 pm
Location: Burlington, VT

[SOLVED] Repeat Region DWMX Problem

Post by saltriver »

feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi All,
I know there are a few DW Haters out there, but please bear with me. I'm trying to do the simplest of things. Repeat Region. I am able to display one record w/o problem:

Code: Select all

<?php require_once('../../Connections/hungryusaconnection.php'); ?>
<?php
$colname_rsmenu = "1";
if (isset($HTTP_GET_VARS['namefield'])) {
  $colname_rsmenu = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['namefield'] : addslashes($HTTP_GET_VARS['namefield']);
}
mysql_select_db($database_hungryusaconnection, $hungryusaconnection);
$query_rsmenu = sprintf("SELECT * FROM menus WHERE item LIKE '%%%s%%' ORDER BY item ASC", $colname_rsmenu);
$rsmenu = mysql_query($query_rsmenu, $hungryusaconnection) or die(mysql_error());
$row_rsmenu = mysql_fetch_assoc($rsmenu);
$totalRows_rsmenu = mysql_num_rows($rsmenu);
mysql_free_result($rsmenu);
?>
<p style="color: #000000"><?php echo $row_rsmenu['item']; ?></p>
But when I add the repeat region, I get the error. Here's the code with the addotion:

Code: Select all

<?php require_once('../../Connections/hungryusaconnection.php'); ?>
<?php
$colname_rsmenu = "1";
if (isset($HTTP_GET_VARS['namefield'])) {
  $colname_rsmenu = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['namefield'] : addslashes($HTTP_GET_VARS['namefield']);
}
mysql_select_db($database_hungryusaconnection, $hungryusaconnection);
$query_rsmenu = sprintf("SELECT * FROM menus WHERE item LIKE '%%%s%%' ORDER BY item ASC", $colname_rsmenu);
$rsmenu = mysql_query($query_rsmenu, $hungryusaconnection) or die(mysql_error());
$row_rsmenu = mysql_fetch_assoc($rsmenu);
$totalRows_rsmenu = mysql_num_rows($rsmenu);
mysql_free_result($rsmenu);
?>
<?php do { ?>
<p style="color: #000000"><?php echo $row_rsmenu['item']; ?></p>
<?php } while ($row_rsmenu = mysql_fetch_assoc($rsmenu)); ?>
I've run into this problem before and I fixed it when I retraced everything, though I don't know how. I guess I need to figure it out now.
I know the variable is being passed and works with URL/GET and FORM/POST. It seems its the DO/WHILE part of DW's repeat region that's making the problem:

Here's the error I get in its entirety:

Code: Select all

Warning:  mysql_fetch_assoc(): 4 is not a valid MySQL result resource in /home/virtual/site110/fst/var/www/html/testing/middle/name_results.php on line 16

Any thoughts?

Steve


feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

The only thing that I see is that you have

Code: Select all

<?php
$row_rsmenu = mysql_fetch_assoc($rsmenu); 
?>
in your code twice
try commenting out the first instance of it(not the one in the while loop) and see if it works.
I think the second one is confused because you have already brought back the results then free the results before you get to the while loop.
Please comment out the following as it then should work.

Code: Select all

<?php
mysql_free_result($rsmenu); 
?>
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

phpScott wrote:The only thing that I see is that you have

Code: Select all

<?php
$row_rsmenu = mysql_fetch_assoc($rsmenu); 
?>
in your code twice
it's ok for DW code
try commenting out the first instance of it(not the one in the while loop) and see if it works.
it won't work. Leave these fetches where they are.
phpScott wrote: I think the second one is confused because you have already brought back the results then free the results before you get to the while loop.
It's the matter.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

been awhile

Post by phpScott »

It had been awhile since I looked at the 'stuff' that DM creates. It doesn't always make sense when you've been coding by hand for so long.

Thanks for pointing out the few things for me.

phpScott
saltriver
Forum Commoner
Posts: 59
Joined: Fri Mar 12, 2004 2:40 pm
Location: Burlington, VT

Post by saltriver »

So Wierdan, do I comment out the last line? I tried deleteing it but I got a parse error. I tried commenting it out w/ // & ##, but they came through as text.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

comment out

Post by phpScott »

try commenting out

Code: Select all

<?php
//$row_rsmenu = mysql_fetch_assoc($rsmenu);
//mysql_free_result($rsmenu);
?>
and see if it works.
lines 10 and 12 in your code with the repeating region.
saltriver
Forum Commoner
Posts: 59
Joined: Fri Mar 12, 2004 2:40 pm
Location: Burlington, VT

Post by saltriver »

Tried that. Back to the first error.
How do I do a "Repeat Region" by hand? I can get the first recordset to show w/ no problem, so if I can do the rest by hand, instead of relying on DW, I should be set. Is IF/WHILE the way to go with that, or is there more than one way. Keep in mind the actual region will be a bit more complex, but all in a table that will repeat.

Steve
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

just make that region in DW, then switch to 'code view' (or do they call it 'source view'?) and delete or comment the line 'mysql_free_result(....'. Commenting it out in design view won't work perhaps. Do not delete nor comment first mysql_fetch_assoc or it won't show you the first record.
saltriver
Forum Commoner
Posts: 59
Joined: Fri Mar 12, 2004 2:40 pm
Location: Burlington, VT

Post by saltriver »

I did do that in code view. It seems tha // works for MySQL commands like $whatever=blah, but putting it in front of

Code: Select all

&#1111;php]<?php &#125; while ($row_rsmenu = mysql_fetch_assoc($rsmenu)); ?>

?>&#1111;/php]
didn't work (neither did #)

Should I be commenting out the entire WHILE line?

Deleteing gave me a parse error, wouldn't commenting do the same?
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Why to you have an closing brace at the start of the loop?. Is there code before that?.
saltriver
Forum Commoner
Posts: 59
Joined: Fri Mar 12, 2004 2:40 pm
Location: Burlington, VT

Post by saltriver »

Here's the line again inbetween the "". I might not be using the Code and PHP buttons correctly:

Code: Select all

&#1111;php]<?php
_____"<?php &#125; while ($row_rsmenu = mysql_fetch_assoc($rsmenu)); ?>"______
?>&#1111;/php]
Does that help. For the complete code see the beggining of the thread.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Not to sure if this would work out, but try it anyway and tell me the results:

Code: Select all

<?php 
do 
{ 
 $row_rsmenu++;
 print('<p style="color: #000000">');
 print($row_rsmenu['item'].'<p>');
}
while ($row_rsmenu = mysql_fetch_assoc($rsmenu));
?>
saltriver
Forum Commoner
Posts: 59
Joined: Fri Mar 12, 2004 2:40 pm
Location: Burlington, VT

Post by saltriver »

I put it in. Here's the code in its entireity:

Code: Select all

<?php require_once('../../Connections/hungryusaconnection.php'); ?>
<?php
$colname_rsmenu = "1";
if (isset($HTTP_GET_VARS['namefield'])) {
  $colname_rsmenu = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['namefield'] : addslashes($HTTP_GET_VARS['namefield']);
}
mysql_select_db($database_hungryusaconnection, $hungryusaconnection);
$query_rsmenu = sprintf("SELECT * FROM menus WHERE item LIKE '%%%s%%' ORDER BY item ASC", $colname_rsmenu);
$rsmenu = mysql_query($query_rsmenu, $hungryusaconnection) or die(mysql_error());
//$row_rsmenu = mysql_fetch_assoc($rsmenu);//
$totalRows_rsmenu = mysql_num_rows($rsmenu);
mysql_free_result($rsmenu);
?>
<?php 
do 
{
$row_rsmenu ++; 
print( '<p style="color: #000000">' ); 
print( $row_rsmenu ['item' ]. '<p>' ); 
}
while ( $row_rsmenu =mysql_fetch_assoc ($rsmenu )); 
?>

I got the original error:

Code: Select all

Warning:  mysql_fetch_assoc(): 4 is not a valid MySQL result resource in /home/virtual/site110/fst/var/www/html/testing/middle/name_results.php on line 21
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

saltriver, please read and try to understand this: Posting Code in the Forums (it's a link)
saltriver
Forum Commoner
Posts: 59
Joined: Fri Mar 12, 2004 2:40 pm
Location: Burlington, VT

Post by saltriver »

So Warnings go in Code Brackets, and PHP Brackets work by themselves?
Post Reply