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!
I need to display <?php echo nl2br($row_getProperties['location']); ?> below on another part of my page in another separate table but as this will take <?php echo nl2br($row_getProperties['location']); ?> out of the loop it will only display the first record. Can anyone tell me how to get around this? I have tried running another loop but I get a conflict on the page and I have tried setting up a separate query and ‘where’ clause but again I end up with various results and none that are satisfactory. I thought that this would be easy enough but as a beginner I see I’m possible wrong.
Thanks for any advice.
B
Define $i to 0 before the loop. Then in the loop create an array like so $array[$i]['location'] and define the value of that key to the current looping var $row_getProperties['location']. Don't forget to add $i++ in there near the end of the loop so the number increases.
This should give you the ability to use all of the location variables the database calls anywhere on your page like so: $array[34]['location'] (that of course would be the 35th location that you extracted from the db).
Thanks so much for you help.
I’m really new to Arrays and Loops and I’m struggling hard to follow your good detailed explanation however I did try an few things and so far this is what I have come up with:
<table>
<tr><td>
<p><strong>Search Found </strong>- </b><?php echo $totalRows_getProperties ?></p>
<p><strong>Facilities in </strong></p>
<p><!--HERE IS WHERE I WANT TO DISPLAY MY NEW LOCATIONS --></p>
</td><td >centre text</td><td>
<?php // if no entry is in db, don't show anything not even the table row
if (!empty($row_getProperties)) {
for ( $i = 0; $array[$i]['location'] = $row_getProperties['location']; $i++ )
do {
echo $array[9]['location'] ; ?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td class="tblbg">Property</td>
</tr>
<tr>
<td><?php echo nl2br($row_getProperties['name']); ?></td>
</tr>
<tr>
<td class="tblbg">Location</td>
</tr>
<tr><!-- LOCATION HERE TO BE MOVED TO OTHER SPOT-->
<td><?php echo nl2br($row_getProperties['location']); ?></td>
</tr>
<tr>
<td class="tblbg">Description</td>
</tr>
<tr>
<td><?php echo nl2br($row_getProperties['description']); ?></td>
</tr>
<tr>
<td class="tblbg">Prices</td>
</tr>
<tr>
<td><?php echo nl2br($row_getProperties['prices']); ?>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<?php } while ($row_getProperties = mysql_fetch_assoc($getProperties)); ?>
<?
} else {
echo ("Sorry there are no matches this time in our database. <br><br> <a href='javascript:history.back()'>Click here</a> to Search Again.");} ?>
</td>
</tr>
</table>
Now I’m sure it’s probably funny what I have tried but maybe if I’m close you can help me further. This at the moment is giving me “Notice: Undefined index: 9 in C:\Inetpub\wwwroot\appartments_php\TMPfgzeplivzx.php on line 372
['location']”
Many thanks once again
B
not be really afraid of...its not an error...its a notice...
its a notice that says that particular variable is not declared.
you have to turn off notices...its enough if you have the warning and errors turned on
feyd, i am not really aware of other situations where notices might be of help.
if you dont mind, can you give me example situations where notices would help to identify holes in the code
Notices are useful. They tell you when variables are not defined, when indexes are not declared. I always put error_reporting(E_ALL); at the top of the script when I'm developing. The goal is to have the most bug-free secure code possible. Say it with me "E_ALL".