Re: Array problem (MySQL/PHP)



Please excuse my previous responce, I hadn't paid enough attention to the
problem and assumed a query was involved.
My bad.
Looking closely now I see something a little curious.
You pass a string to 'TableData()'. 'TableData()' then attempts to extract
a string from the associated array '$row_Recordset1' using '$slot' as the
key.
However, the first access of '$row_Recordset1' is meant to assign a value to
'$slotuser' which, if it's name is meaningful, is unlikely to be a date.
If no string is assigned from this first attempt then in the 'else' block
the same value (as returned from the same array '$row_Recordset1', with the
same key '$slot') is appended to the end of that returned string. However,
the first 'if' test has detirmined that that element of the array is empty,
or doesn't exist.
From what I can see if the first 'if' block found no value to assign from
'$row_Recordset1' using '$slot' as the key, then it certainly won't do so in
the 'else' block either, as nothing has altered the values in
'$row_Recordset1' or '$slot' within the function. Same evaluation, same
result.
In the 'if' block you seem to be looking to extract a string from
'$row_Recordset1' using the key '$slot', and in the 'else' block you are
trying to extract a date using the same array and key?
Having said all that, I'm not sure why '$slot', when assigned the
appropriate value, does not work as a key into the array.


"BlackSpider" <BlackSpider@xxxxxxxxxxxxxxxx> wrote in message
news:v5ednayzlo_lYr_YRVnytQ@xxxxxxxxxxxxxxxxx
<--PHP
function TableData($slot)
{
global $row_Recordset1, $colour_FREE, $colour_TOOK;

$slotuser = $row_Recordset1[$slot];
if ($slotuser == "") {
return ($colour_FREE.'" class="timeslot"><div
align="center">'.$slotuser );
}
else {
return ($colour_TOOK . '" class="timeslot"><div align="center">' .
$row_Recordset1[ $slot ]);
}

}
PHP-->

The $row_Recordset1 array is set by mysql_fetch_assoc to get some table
data, and I call this function with the table-row name (In this case
"date"), like this: TableData('date')

However, when trying to get the data of the row 'date' from the Record
using
$slot, it returns a null string, regardless of what data is actually
there.
If I replace $slot with 'date' in the code, it returns the correct value,
so
the connection between php/Mysql is fine, but when trying to get the data
by
using a String as the Key, it simply doesn' twork. Any ideas?


HTH
Vince Morgan


.



Relevant Pages

  • Newbie: Array of pointers to strings questions.
    ... What I'm trying to do is extract information from one file and insert ... and the information in each case is extracted as a string. ... the relevant file is read into a temp file, ... but handling the array was a problem. ...
    (comp.lang.c)
  • Help in French|Spanish|German translation.
    ... I am also an author of User-defined string functions. ... WORDTRANEX (cSearched, cArExpressionSought | cExpressionSough, ... each string of the array is searched ... If the parameter nArStartOccurrence is -1 or omitted, the replacement starts ...
    (microsoft.public.fox.helpwanted)
  • Re: Function returns Datatype Mismatch
    ... >> Public Function Extract(Account_Code As String) As String ... Tokens is an array of strings, ... > Extract = Tokens ... > Tokensyields "A" ...
    (microsoft.public.access.modulesdaovba)
  • Re: Function returns Datatype Mismatch
    ... > Public Function Extract(Account_Code As String) As String ... Tokens is an array of strings, ... Extract = Tokens ... Tokensyields "A" ...
    (microsoft.public.access.modulesdaovba)
  • Re: passing a string to a dll
    ... Joe, I really appreciate you taking the time to demonstrate this. ... sure how I would implement indexing it for random alphanumeric codes. ... I might handle the array. ... I actually have been wondering if I could use a second string ...
    (microsoft.public.vc.mfc)