SitePoint Sponsor |
|
User Tag List
Results 1 to 10 of 10
Thread: A really basic question ....
-
Jun 9, 2002, 14:16 #1
- Join Date
- Mar 2002
- Posts
- 116
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
A really basic question ....
Ok, should be simple.
I have got my website with my database and PHP.
I have a table with 4 values in a column.
I do mysql_fetch_array and I get all these 4 values in an array that thanks to Keving Yank's book I know how to print on screen.
But how can I take them and put them each in a different variable ??
Like time0, time1, time3, time4 ???
Thanks, please help me out, thanks,
Andrea
-
Jun 9, 2002, 17:15 #2
What exactly do you mean?
If I understand you correctly I would do something like this.
PHP Code:$s = mysql_query("SELECT * FROM table");
while ($r = mysql_fetch_array($s)) {
$time0 = $r[0];
$time1 = $r[1];
$time2 = $r[2];
$time3 = $r[3];
}
echo $time2; // or something like that.
- the lid is off the maple syrup again!
-
Jun 9, 2002, 20:06 #3
- Join Date
- Mar 2002
- Location
- Columbia, South Carolina
- Posts
- 304
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally posted by notepad_coder
What exactly do you mean?
If I understand you correctly I would do something like this.
PHP Code:$s = mysql_query("SELECT * FROM table");
while ($r = mysql_fetch_array($s)) {
$time0 = $r[0];
$time1 = $r[1];
$time2 = $r[2];
$time3 = $r[3];
}
echo $time2; // or something like that.
PHP Code:$s = mysql_query("SELECT * FROM table");
while ($r = mysql_fetch_array($s)) {
$time0 = $r[0];
$time1 = $r[1];
$time2 = $r[2];
$time3 = $r[3];
echo $time2; // or something like that.
}
-
Jun 9, 2002, 20:34 #4
they are right. why don't you just use the array's index instead of assigning it to a new variable, this way you can save computer memory.
-
Jun 9, 2002, 21:38 #5
- Join Date
- Jul 2001
- Location
- Missouri
- Posts
- 3,428
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Re: A really basic question ....
Originally posted by powergen
I have a table with 4 values in a column.- Matt** Ignore old signature for now... **
Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
"Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR
-
Jun 9, 2002, 23:18 #6
- Join Date
- Mar 2002
- Posts
- 116
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks !!!
Yes, I could put 4 values in 4 colums but would I call 4 SELECT then ???
This way I do just 1 SELECT .... I'm new ... =)
Which one do you think it's best being probably this script really a lot run on my server ?
-
Jun 9, 2002, 23:20 #7
- Join Date
- Jul 2001
- Location
- Missouri
- Posts
- 3,428
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
no, not 4 SELECTs. just
SELECT col1, col2, col3, col4 FROM table
-
Jun 9, 2002, 23:27 #8
- Join Date
- Mar 2002
- Posts
- 116
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Jorasmi, yes, the array has an internal index but as far as I have tried ... I have never got it to work right ....
Here's what I have written ...
PHP Code:<?php
$times = @mysql_query("SELECT times FROM betasom_time");
if (!$times) {
echo( "<p>Unable to locate the " .
"times table at this time.</p>" );
exit();
}
while ( $row = mysql_fetch_array($times) ) {
echo("<p>" . $row[times] . "</p>");
}
echo($row[0]);
echo($row[1]);
echo($row[2]);
echo($row[3]);
$time =( date("Hi") );
echo ($time);
?>
I bet it's wrong ... but I don't know why ..
Andrea
-
Jun 9, 2002, 23:47 #9
- Join Date
- Mar 2002
- Posts
- 116
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ok, I have just tried on my online server ... no result ... I have to keep the echos in the while loop.
But aren't variables kept in memory ?
Apparently not ... or just arrays are forgettable ?
I have also tried to insert these echos in the while loop but I get just the first echo[0] all other values appear as empty.
The while loop just use the first compartment of the array and doesn't advance ...
Can this be a problem of setting the table and column ?
-
Jun 10, 2002, 01:30 #10
- Join Date
- Mar 2002
- Posts
- 116
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ok, here's it!
I just created 4 different columns as you have told me and added those 4 values in them.
I just wonder why the array didn't have internal numbers to let me recall values....
The column didn't have ID of sort ... could it be this ?
Anyway .. aren't internal positions in arrays automatically created or they are table/column dependent ??
PHP Code:
while ( $row = mysql_fetch_array($times) ) {
$dawn = $row[dawn];
$morning = $row[morning];
$dusk = $row[dusk];
$night = $row[night];
}
echo ('<p>' . ($dawn) . '</p>');
echo ('<p>' . ($morning) . '</p>');
echo ('<p>' . ($dusk) . '</p>');
echo ('<p>' . ($night) . '</p>');
Again THANKS for your help !!!
Andrea
Bookmarks