Jump to content

Need help accessing array variable AFTER iteration


sptrsn

Recommended Posts

I have an array of property details that prints to the page.

 

Later on that same page, I would like to use one of the array's values as part of a mailto script, but I can't seem to figure out how to recall it.

 

could someone point me in the direction of how I can make the array's values available for later use?

 

I hope this is clear enough.

 

Thanks 

Link to comment
Share on other sites

yes. The array is the result of a db query.

Here's the query..

<?php
$query = "select * from daily where id='$id'";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$details='<ul class="pageitem">';
$details.='<li class="menu"><span class="name"><a href="http://maps.google.com/maps?q='.$row['address'].', '.$row['city'].'">'.$row['address'].', '.$row['city'].'</a></li>';
$details.='<li class="menu"><span class="name">APN:#'.$row['apn'].' -- '.$row['subdivision'].'</li>';
$details.='<li class="menu"><span class="name">SqFt: '.$row['sqft'].'('.$row['level'].') Built: '.$row['yr_built'].' Pool: '.$row['pool'].' Lot: '.$row['lot'].'   </li>';
$details.='</ul>';
$details.='<ul class="pageitem">';
$details.='<li class="menu"><span class="name">Open Bid: $'.number_format($row['open_bid'],0,'.', ',').'</li>';
$details.='<li class="menu"><span class="name">$/SqFt: $'.number_format($row['price_sqft'],0,'.', ',').'</li>';
$details.='<li class="menu"><span class="name">Equity: $'.number_format($row['equity']*100,0,'.', ',').'%</li>';
$details.='<li class="menu"><span class="name">EstValue: $'.number_format($row['est_value'],0,'.', ',').'</li>';
$details.='<li class="menu"><span class="name">AVM: $'.number_format($row['avm'],0,'.', ',').'</li>';
$details.='</ul>';
$details.='<ul class="pageitem">';
$details.='<li class="menu"><span class="name">'.$row['trustee_name'].' -'.$row['time'].'</li>';
$details.='</ul>';
echo($details);
}
?>

 

Then, at the bottom of the page, I have a pop up window that I am using to generate emails for different purposes, where I have the subject line, and I want to append it with the address of the property on that page. thusly...

 

<ul class="pageitem">
<li class="menu"><a class="noeffect" onclick="iWebkit.popup('popup1')">Select an Actvity</span></a></li>
</ul>

<div id="popup1" class="popup">
<div id="frame" class="confirm_screen">
	<span>Activities</span>

<a href="mailto:steve@myemail.com?subject=Request Info on.....ADD ADDRESS VARIABLE HERE!!.....">    
<span class="gray">Request Info</span></a>

<a class="noeffect" onclick="iWebkit.closepopup(event)"><span class="black">Cancel</span></a>

Link to comment
Share on other sites

It appears you expect the query to return only one record from the database, correct? If so, you can eliminate the while loop, and you can just access the value you want from the array that was returned from the query, $row['address']. If that isn't the case, and the query is returning multiple records, you'll need to either run a query selecting the field from the specific record you want, or use mysql_data_seek() to get back to the right spot in the result set.

 

<a href="mailto:steve@myemail.com?subject=Request Info on <?php echo !empty($row['address']) ? {$row['address']} : 'ENTER A DEFAULT VALUE HERE'; ?>">

Link to comment
Share on other sites

You are correct. I am only fetching one record from the database. It hadn't even occurred to me that I didn't need to use the while loop. I'm obviously not a programmer, so I just kept reusing code that worked for on other pages. I'm not even sure how to call for the data if I don't use my "tried and true" little snippet of code. But I'm willing to try. Perhaps that way, as you suggest, I can have the variable available anywhere on the page.

 

I'll give it a try. Thank you.

Link to comment
Share on other sites

Yes I did thank you. I stripped out all the "while loop" stuff, echo'd some simple stuff then got the mailto part working.

Now I'm trying rebuild the array formatting since it's completely different that what I've been using. Making progress.

Thanks again.

Link to comment
Share on other sites

Thank you very much Pikachu2000. I got it working with your input and learned a few things at the same time. that's a Beautiful thing!

Here's what I have....

<?php
$query = "select * from daily where id='$id'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
echo '<ul class="pageitem">';
echo '<li class="menu"><span class="name"><a href="http://maps.google.com/maps?q='.$row['address'].', '.$row['city'].'">'.$row['address'].', '.$row['city'].'	</a></li>';
echo '<li class="menu"><span class="name">APN:#'.$row['apn'].' -- '.$row['subdivision'].'</li>';
echo '<li class="menu"><span class="name">SqFt: '.$row['sqft'].'('.$row['level'].') Built: '.$row['yr_built'].' Pool: '.$row['pool'].' Lot: '.$row['lot'].'   </li>';
echo '</ul>';
echo '<ul class="pageitem">';
echo '<li class="menu"><span class="name">Open Bid: $'.number_format($row['open_bid'],0,'.', ',').'</li>';
echo '<li class="menu"><span class="name">$/SqFt: $'.number_format($row['price_sqft'],0,'.', ',').'</li>';
echo '<li class="menu"><span class="name">Equity: $'.number_format($row['equity']*100,0,'.', ',').'%</li>';
echo '<li class="menu"><span class="name">NVC Value: $'.number_format($row['est_value'],0,'.', ',').'</li>';
echo '<li class="menu"><span class="name">AVM: $'.number_format($row['avm'],0,'.', ',').'</li>';
echo '</ul>';
echo '<ul class="pageitem">';
echo '<li class="menu"><span class="name">'.$row['trustee_name'].' -'.$row['time'].'</li>';
echo '</ul>';
?>

 

And while my mailto line is less than elegant... it works.

<a href="mailto:steve@myemail.com?subject=INFO REQUEST-- <?echo $row['address'];echo ', ';echo $row['city'];echo '--  '; echo date("l F d, Y, h:i A");?>">

 

Every time I treid to concatenate those variables in the mailto, it threw some kind of error. So I'll just role with this for now.

 

Thanks again.

Link to comment
Share on other sites

When you echo array elements within a quoted string, and they have a quoted index value, you need to use 'complex notation' and enclose the element in curly braces. The php function still needs to be concatenated, or assign its output to a variable before the string is echoed.

 

<?php echo "{$row['address']}, {$row['city']}--  " . date('l F d, Y, h:i A');?>

 

OR

 

$date = date('l F d, Y, h:i A');
<?php echo "{$row['address']}, {$row['city']}--  $date");?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.