SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Mar 2002
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 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

  2. #2
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    Location
    Colorado
    Posts
    835
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!

  3. #3
    SitePoint Addict Clete2's Avatar
    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. 
    more like:

    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 echo needs to be INSIDE the {}'s... else it'd echo the last result
    My Blog
    My Photography Website
    Linux user #339185

  4. #4
    web daemon jorasmi's Avatar
    Join Date
    Nov 2001
    Location
    Philippines
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    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.
    there's the problem. put the 4 values in 4 columns.
    - 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

  6. #6
    SitePoint Zealot
    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 ?

  7. #7
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    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


  8. #8
    SitePoint Zealot
    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

  9. #9
    SitePoint Zealot
    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 ?

  10. #10
    SitePoint Zealot
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •