SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Best way to change Digit value to String?

    What is the best way to go about this, I feel like Im doing it all wrong with an if statement that takes up a generous amount of space.

    PHP Code:
    $sql "SELECT * FROM notes";
    $result mysql_query($sql);

        while (
    $query mysql_fetch_array($result)) {
            
    $list[] = $query;
        }

    for (
    $i 0$i count($list); $i++) {
    if (
    $list[$i] == '1') {$list[$i] == 'Name'}
    if (
    $list[$i] == '2') {$list[$i] == 'Note'}
    if (
    $list[$i] == '3') {$list[$i] == 'Etc'}

    Know what I mean?

    Can i do like a case/switch would that be better?
    Or maybe compare two arrays? array(1\,2,3,4,5) and array(name, note, etc etc etc)

    orr is there like a reference variable? $$list[$i]

  2. #2
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are Name, Notes, Etc fields in the notes table? What are you trying to achieve? Your $list array will be a nested array because $query is an array.
    PHP Code:
    Array(
    [
    0] => Array([0] => fieldname1, [1] => fieldname2, [2] => fieldname3)
    [
    1] => Array([0] => fieldname1, [1] => fieldname2, [2] => fieldname3)
    [
    2] => Array([0] => fieldname1, [1] => fieldname2, [2] => fieldname3)
    ); 

  3. #3
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ohhhh that works nice thak you!!


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
  •