Need to repeat a mysql region. Recordsets frees to early

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Slason
Forum Newbie
Posts: 5
Joined: Thu Jan 26, 2012 3:44 pm

Need to repeat a mysql region. Recordsets frees to early

Post by Slason »

Hey,

My issue it that I try to repeat a mysql region with such a code:

Code: Select all

 
do  {
}while ($row_get_recordset = mysql_fetch_assoc($get_recordset));
I would like to repeat only the
<td>' . $row_get_info['spesifikk'] . ' </td>
of

Code: Select all

	if ($currentcategory == 7)
		{
//getinfo	
mysql_select_db($database_hardware, $hardware);
$query_get_info = 'SELECT c.name, d.name as "developername", d.webpage as "developerweb", s.name as "spesifikk", c.photo, c.description
FROM chasis_has_spesifikkstandard cas
JOIN chasis c ON cas.chasis_id = c.id
JOIN developer d ON c.developer_iddeveloper = d.iddeveloper
JOIN spesifikkstandard s ON cas.spesifikkstandard_idstandard = s.idstandard
WHERE c.id = ' . $currentid . '';
$get_info = mysql_query($query_get_info, $hardware) or die(mysql_error());
$row_get_info = mysql_fetch_assoc($get_info);	
		
		$hardwareinfo.='
		<table>
			<tr>
				<td>Name</td>
				<td>' . $row_get_info['name'] . ' </td>
				<td colspan="5" rowspan="8" valign="right" align="right" ><img height="170px" width = "200px" src="images/hardware/' . $row_get_info['photo'] . '" /></td>
			</tr>
			<tr>
				<td>Developer</td>
				<td><a href="' . $row_get_info['developerweb'] . '">' . $row_get_info['developername'] . ' </a></td>
			</tr>
			<tr>
				<td>Supported cards</td>
				<td>' . $row_get_info['spesifikk'] . ' </td>
			</tr>
            	<td colspan="2" width="430px" height="200px" valign="top">
   					<p><br  /></p>
                    <div style="text-wrap:normal">
      					' . $row_get_info['description'] . '
   					</div>
			</td>
            <tr>
		</table>';
			
		}

Later I use

Code: Select all

echo $hardwareinfo;
in my index.php.

I tried to edit the code like this:

Code: Select all

	if ($currentcategory == 7)
		{
//getinfo	
mysql_select_db($database_hardware, $hardware);
$query_get_info = 'SELECT c.name, d.name as "developername", d.webpage as "developerweb", s.name as "spesifikk", c.photo, c.description
FROM chasis_has_spesifikkstandard cas
JOIN chasis c ON cas.chasis_id = c.id
JOIN developer d ON c.developer_iddeveloper = d.iddeveloper
JOIN spesifikkstandard s ON cas.spesifikkstandard_idstandard = s.idstandard
WHERE c.id = ' . $currentid . '';
$get_info = mysql_query($query_get_info, $hardware) or die(mysql_error());
$row_get_info = mysql_fetch_assoc($get_info);	
		
		$supported = '';
		do {
		$supported .= '<td>' . $row_get_info['spesifikk'] . ' </td>';
		 }while ($row_get_info = mysql_fetch_assoc($get_info));
		 
		$hardwareinfo.='
		<table>
			<tr>
				<td>Navn</td>
				<td>' . $row_get_info['name'] . ' </td>
				<td colspan="5" rowspan="8" valign="right" align="right" ><img height="170px" width = "200px" src="images/hardware/' . $row_get_info['photo'] . '" /></td>
			</tr>
			<tr>
				<td>Utvikler</td>
				<td><a href="' . $row_get_info['developerweb'] . '">' . $row_get_info['developername'] . ' </a></td>
			</tr>
			<tr>
				<td>Støttet hovedkorttyper</td>
				' . $supported . '
			</tr>
            	<td colspan="2" width="430px" height="200px" valign="top">
   					<p><br  /></p>
                    <div style="text-wrap:normal">
      					' . $row_get_info['description'] . '
   					</div>
			</td>
            <tr>
		</table>';
			
		}
but then

Code: Select all

 
do  {
}while ($row_get_info = mysql_fetch_assoc($get_info));
frees the data to early, and I get no data printed.

Any suggestions on how I can solve this? First time php, and I appoligies for any obvious mistakes. :)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Need to repeat a mysql region. Recordsets frees to early

Post by Christopher »

I am confused about this part of your question:
Slason wrote:I would like to repeat only the

<td>' . $row_get_info['spesifikk'] . ' </td>
The select will select records containing the fields you specify. Each row will have a $row_get_info['spesifikk'] field. So what is it you want to do?
(#10850)
Slason
Forum Newbie
Posts: 5
Joined: Thu Jan 26, 2012 3:44 pm

Re: Need to repeat a mysql region. Recordsets frees to early

Post by Slason »

Was not sure how to explain my problem. Solved it tho, was a line missing.
Post Reply