I did var_dump on the result resource and I got resource(5) of type (mysql
result).
--- Begin Message ---
On Mar 26, 2008, at 12:30 PM, Evert Lammerts wrote:
OK. Tried that and count comes back as 1.
So your query returns only one record. Try
$query ="Select answer from answers";
Why
Richard Dunne wrote:
Using this extract from
http://ie.php.net/manual/en/control-structures.foreach.php
Amaroq
09-Mar-2008 06:40
Even if an array has only one value, it is still an array and foreach will run it.
The above code outputs:
I'm an array.
-
So
ction) or die(mysql_error());
> while($row = mysql_fetch_assoc($result))
> {
>foreach($row as $answer)
>{
>echo $answer . "\n";
>}
> }
> I thought I would be able to print out each array element, but I am not
> getting an
e able to print out each array element, but I am not
> getting any output. Has anyone got a better idea?
>
>
> -- Forwarded message --
> From: Evert Lammerts <[EMAIL PROTECTED]>
> To: Richard Dunne <[EMAIL PROTECTED]>
> Date: Wed, 26 Mar 2008 18:22:5
Using this extract from
http://ie.php.net/manual/en/control-structures.foreach.php
Amaroq
09-Mar-2008 06:40
Even if an array has only one value, it is still an array and foreach will run
it.
The above code outputs:
I'm an array.
-
So if I use:
$query = "Se
The semi-colon is gone, although I didn't even notice it! I am using two
different queries, one for count and the other to access the data itself.
After running mysql_fetch_assoc, is foreach ok for accessing array members, or
is there a more subtle approach?
So it's working now? If it is, yo
- Original Message -
From: Evert Lammerts <[EMAIL PROTECTED]>
Date: Wednesday, March 26, 2008 5:22 pm
Subject: Re: [PHP-DB] numeric string to single digit array
>
> > Tried that as well and got the same result.
> > I tried "Select count(answer) as total from
Tried that as well and got the same result.
I tried "Select count(answer) as total from answers where studentID='A123456789'";
from the CLI and got total = 2 as a result.
So, we got rid of the Invalid Resource error and we know that the
student id you use occurs in both rows in your tabl
- Original Message -
From: Evert Lammerts <[EMAIL PROTECTED]>
Date: Wednesday, March 26, 2008 4:30 pm
Subject: Re: [PHP-DB] numeric string to single digit array
>
> >
> > OK. Tried that and count comes back as 1.
> >
>
> So your query returns
On Mar 26, 2008, at 12:30 PM, Evert Lammerts wrote:
OK. Tried that and count comes back as 1.
So your query returns only one record. Try
$query ="Select answer from answers";
Why not do a var_dump() on $result to verify that it
is a mysql result resource and then verify the count
of rows
OK. Tried that and count comes back as 1.
So your query returns only one record. Try
$query ="Select answer from answers";
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
- Original Message -
From: Evert Lammerts <[EMAIL PROTECTED]>
Date: Wednesday, March 26, 2008 4:04 pm
Subject: Re: [PHP-DB] numeric string to single digit array
>
> > This is my code. The only error is at line 15 as I stated above.
> >
> > 1 > 2 DEFI
Evert Lammerts wrote:
>
>> This is my code. The only error is at line 15 as I stated above.
>>
>> 1 > 2 DEFINE ("host","localhost");
>> 3 DEFINE ("user","root");
>> 4 DEFINE ("password","password");
>> 5 DEFINE ("database","questions");
>> 6
>> 7 $connection=mysql_connect(host,user,password) or d
This is my code. The only error is at line 15 as I stated above.
1
Turn line 13 into
$result = mysql_query($query) or die(mysql_error());
, so leave out the connection parameter and append the die() function,
and see what error that produces.
--
PHP Database Mailing List (http://www.
- Original Message -
From: Evert Lammerts <[EMAIL PROTECTED]>
Date: Wednesday, March 26, 2008 3:39 pm
Subject: Re: [PHP-DB] numeric string to single digit array
>
> > PHP is telling me that the resource I am using for
> mysql_fetch_assoc is invalid:
> >
> &g
PHP is telling me that the resource I am using for mysql_fetch_assoc is invalid:
$query ="Select answer from answers where studentID ='A123456789'";
$result = mysql_query($query,$connection);
$count=0;
while($row = mysql_fetch_assoc($result));
{
$count++;
}
echo $count;
Are you sure your d
- Original Message -
From: Evert Lammerts <[EMAIL PROTECTED]>
Date: Wednesday, March 26, 2008 3:12 pm
Subject: Re: [PHP-DB] numeric string to single digit array
>
> > I ran this
> >
> > $query ="Select answer from answers where studentID ='A12345678
I ran this
$query ="Select answer from answers where studentID ='A123456789'";
$result = mysql_query($query,$connection);
$resultArray = str_split($result,1);
$count = count($resultArray);
Where's the fetch?
|$result = mysql_query("SELECT answer FROM answers WHERE studentID =
'A123456789
- Original Message -
From: Chris <[EMAIL PROTECTED]>
Date: Wednesday, March 26, 2008 2:18 am
Subject: Re: [PHP-DB] numeric string to single digit array
> Richard Dunne wrote:
> > Sorry for the top-posting, it's my mail client, not my design.
> I honestly
Richard Dunne wrote:
Sorry for the top-posting, it's my mail client, not my design. I honestly have not even looked at myphpadmin much, using the CLI mostly.
It's easy enough to click to another place in your mail client ;)
So what happens when you run that query manually?
--
Postgresql &
Sorry for the top-posting, it's my mail client, not my design. I honestly have
not even looked at myphpadmin much, using the CLI mostly.
- Original Message -
From: Chris <[EMAIL PROTECTED]>
Date: Wednesday, March 26, 2008 0:53 am
Subject: Re: [PHP-DB] numeric string to s
Please always CC the mailing list so others can learn and also
contribute answers.
Also please don't top-post as it makes it hard to follow discussions.
Richard Dunne wrote:
I am using MySQL and retrieving a single column which consists of single digit
integers. I have been doing a lot of
Richard Dunne wrote:
Can anyone tell me how how to convert a string of integers into an array of single digit
integers. i.e. "1223123" into ['1','2,','2','3','1,'2','3'] ?
$string = '12345';
$array = array();
for ($i = 0; $i < strlen($string); $i++) {
$array[] = $string[$i];
}
I'm sure the
23 matches
Mail list logo