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!
So I've been trying to get this array working for a few days and I'm not having any luck at all. I'm a cold fusion programmer discovering PHP and I haven't been able to find a good resource on arrays for PHP. Does anyone have any good sources. The php.net explnations seem to be a little to cryptic for me.
The code I'm using is below if anyone has any other ideas. Im trying to load a sort order variable into an array so i can loop through the update statement when new values have been selected from the sort drop downs...
<?php if ($update == "true") echo print_r($sortlist);
//array loop will go here and update the database once i figure it out
//mysql_query("UPDATE PAGE_CONTENT SET
// SORT = '$sort'
// WHERE CONTENT_ID=$content_id")
// or die ('could not update');
?>
<form action="index.php?fuseaction=admin_company.sort&page_id=<?php echo "$page_id";?>&update=true" method="post">
<?php
//grab the content and loop through order by the sort column
$Result = mysql_query("SELECT * FROM PAGE_CONTENT WHERE PAGE_ID=$page_id order by SORT");
while ($Row = mysql_fetch_row($Result))
//output the content
{
if (strlen($Rowї2]) > 0 ) echo "<h1>$Rowї2]</h1>";
if (strlen($Rowї3]) > 0 ) echo "<h2>$Rowї3]</h2>";
if (strlen($Rowї4]) > 0 ) echo "<p>$Rowї4]</p>";
if (strlen($Rowї5]) > 0 ) echo"<img src="uploads/$Rowї5]" border=0 alt="Rowї8]"></a><br><br>";
if ($Rowї6] <> "") echo "<a href="$Rowї6]" target="_new"><font class=boxtext>more >></font></a><br>";
if ($Rowї7] <> "") echo "<a mailto="$Rowї7]"><font class=boxtext>$Rowї7]</font></a><br>";
echo"<input type="hidden" name="content_id" value="$Rowї0]">";
$sort=$Rowї14];
$mylist=$Rowї0];
//load the sort order drop down
echo "<font class=data>sorted as:</font>
<select name="sort">";
$Result2 = mysql_query("SELECT SORT FROM PAGE_CONTENT WHERE PAGE_ID=$page_id");
while ($Row = mysql_fetch_row($Result2))
{
print"<option value="$Rowї0]" "; if ($Rowї0] == $sort) echo "selected"; echo">$Rowї0]</option>";
}
echo"</select> <br><br>";
//load the array to pass to the update statement
$sortlistї]= array($sort);
//output the array for testing purposes as it is being loadded
echo print_r($sortlist);
}
//load the hidden field with array values
echo "<input type="hidden" name="real_list" value="";echo $sortlist; echo"">";
?>
What array are you talking about? The mysql_fetch_row one?
How are you passing the variables to the update portion of the script? If you are using the form, you should be aware that $row[] will not automatically pass to the next page. You have to define the variables with input types and then access them with $_GET or $_POST.
I have sympathy, seeing as I came from ColdFusion myself, but we need a bit more information as to what you are trying to do
//load the sort order drop down
echo "<font class=data>sorted as:</font>
<select name="sort">";
$Result2 = mysql_query("SELECT SORT FROM PAGE_CONTENT WHERE PAGE_ID=$page_id");
while ($Row = mysql_fetch_row($Result2))
{
print"<option value="$Rowї0]" "; if ($Rowї0] == $sort) echo "selected"; echo">$Rowї0]</option>";
}
echo"</select> <br><br>";
//load the array to pass to the update statement
$sortlistї]= array($sort);
//output the array for testing purposes as it is being loadded
echo print_r($sortlist);
//load the hidden field with array values
echo "<input type="hidden" name="real_list" value="";echo $sortlist; echo"">";
It's being past through the hidden field above. The problem I am having mostly is just in loading this arrary, it seems to work somewhat but the output of the array that i echo with the "print_r" doesn't look right. The form submits to itself with the update variable set to true, so it can then loop over that array in the update statement at the top.
Does anyone know of a good source for learning arrays in PHP other then http://www.php.net
I've looked thorugh that a few times and I just can't seem to figure it out, it might be over my head a little bit.
I just need to load a variable into an array or list from a while loop, then pass the values through a form, and then loop over the array with an update statement.
I don't know of any resources, myself I find arrays with PHP to be very good in functionality and felxibility, especially cool (and sometimes frustrating) the mix of associative and indexed
I think you missunderstand slightly..
$var[] = 'something';
will add another value to the array $var
$var = array('something');
will make $var an array with one string element
so when you are doing
$var[] = array('someval');
You are creating an array with one string element and appending it to the $var array, meaning that if the indexposition happened to be 5 it would be true on
if ($var[5]['0] === 'someval') ...
Unfortunatley this doesn't seem to work it error at the second = sign, as did the example code from codewalkers when i plugged it in. Is this close, I need to create and loop over this array and insert the sort id into the database where content_id=$content_id$ from the array. It's clearing up some but still a little muddled for me.
would be the same as
$sortlist = array( array( 'order' => $sort, 'price' => $content_id ))
(since your index id is 0)
and can be acessed like
$sortlist[0]['price']
$sortlist[0]['order']