Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    New Coder
    Join Date
    May 2009
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    mysql_query for State flag

    I have a site that has the 50 US States and I would like to have that States flag show when it is selected.

    Would this work? if not what needs to be added or deleted?

    Right now I have say Alabama in a directory called flags and Alabama is 1.gif. How when I select Alabama from the main page that Alabama's page opens with its flag shown in the header?

    PHP Code:
    <?php
    if (is_file("city/$xcityid.gif")) { include("city/$xcityid.gif"); }
    ?>
    $xcityid is the variable that is mysql_query for State name.

  • #2
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,547
    Thanks
    57
    Thanked 148 Times in 147 Posts
    try

    PHP Code:
    <?php

    // goping on "$xcityid is the variable that is mysql_query for State name." State name = Alabama? or 1?
    $states = array("alabama""alaska"); // im from UK not a clue lol
    foreach($states as $numberRepresentingState => $state)
    {
        if(
    $state==$xcityid)
        {
            
    $xcityidNo $numberRepresentingState;
            break;
        }
    }

    //alabama would be 1, alaska would be 2
    // so below alabama would be 1.gif

    if (file_exists("city/".$xcityidNo.".gif")) 

        echo 
    "<img src=\"city/".$xcityidNo.".gif\" width=\"100\" height=\"100\" alt=\"".$xcityid." state flag\" />";
    }
    ?>
    Last edited by Phil Jackson; 10-19-2009 at 07:16 PM.
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #3
    New Coder
    Join Date
    May 2009
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Phil Jackson View Post
    try

    PHP Code:
    <?php

    // goping on "$xcityid is the variable that is mysql_query for State name." State name = Alabama? or 1?
    $states = array("alabama""alaska"); // im from UK not a clue lol
    foreach($states as $numberRepresentingState => $state)
    {
        if(
    $state==$xcityid)
        {
            
    $xcityidNo $numberRepresentingState;
            break;
        }
    }

    //alabama would be 1, alaska would be 2
    // so below alabama would be 1.gif

    if (file_exists("city/".$xcityidNo.".gif")) 

        echo 
    "<img src=\"city/".$xcityidNo.".gif\" width=\"100\" height=\"100\" alt=\"".$xcityid." state flag\" />";
    }
    ?>
    From what I see here I will have to generate each state and state flag #? I was hoping that since the States are alread in the dB I would only need to add a query for the image located in the dir Flags.

  • #4
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,547
    Thanks
    57
    Thanked 148 Times in 147 Posts
    then create a new row in database, say imgId 001, 002, 003

    PHP Code:
    if (file_exists("city/".$imgId.".gif"))  
    {  
        echo 
    "<img src=\"city/".$imgId.".gif\" width=\"100\" height=\"100\" alt=\"".$xcityid." state flag\" />"

    ?> 
    should output

    Code:
    <img src="city/001.gif" width="100" height="100" alt="Alabam state flag" />
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #5
    New Coder
    Join Date
    May 2009
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Phil Jackson View Post
    then create a new row in database, say imgId 001, 002, 003

    PHP Code:
    if (file_exists("city/".$imgId.".gif"))  
    {  
        echo 
    "<img src=\"city/".$imgId.".gif\" width=\"100\" height=\"100\" alt=\"".$xcityid." state flag\" />"

    ?> 
    should output

    Code:
    <img src="city/001.gif" width="100" height="100" alt="Alabam state flag" />
    What would the settings be in the dB? VAR?

  • #6
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,547
    Thanks
    57
    Thanked 148 Times in 147 Posts
    just use text or var its only to stick a lil somet in, int will do.
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #7
    New Coder
    Join Date
    May 2009
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Code has been installed but no image shows.

  • #8
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,547
    Thanks
    57
    Thanked 148 Times in 147 Posts
    right click view source paste me the bit about the image.
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #9
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,547
    Thanks
    57
    Thanked 148 Times in 147 Posts
    and change this to:

    PHP Code:
    if (file_exists("city/".$imgId.".gif"))   
    {   
        echo 
    "<img src=\"city/".$imgId.".gif\" width=\"100\" height=\"100\" alt=\"".$xcityid." state flag\" />";  
    }
    else
    {
        echo 
    "city/".$imgId.".gif does not exist";
    }
    ?> 
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #10
    New Coder
    Join Date
    May 2009
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Phil Jackson View Post
    and change this to:

    PHP Code:
    if (file_exists("city/".$imgId.".gif"))   
    {   
        echo 
    "<img src=\"city/".$imgId.".gif\" width=\"100\" height=\"100\" alt=\"".$xcityid." state flag\" />";  
    }
    else
    {
        echo 
    "city/".$imgId.".gif does not exist";
    }
    ?> 
    I get this on the main page now

    city/.gif does not exist

  • #11
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,547
    Thanks
    57
    Thanked 148 Times in 147 Posts
    i need to see more of your code.

    PHP Code:
    $imgId 
    has no value
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #12
    New Coder
    Join Date
    May 2009
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php if ($beta) {?>
    <div style="background-color: lightyellow; border-bottom: 1px solid brown; text-align: center; padding: 10px 0px; margin-bottom: 10px; font-size: 12px; color: crimson; font-weight: bold;">
    This demo contains features in beta that may not be present in the <a href="http://xzeroscripts.com/demos/xzero_classifieds/">script available for purchase</a> at this time.
    </div>
    <?php }?>

    <table width="100%"  border="0" cellspacing="0" cellpadding="0" id="header">

    <tr><td>

    <div id="logo">
     <br />

    <?php
    // going on "$xcityid is the variable that is mysql_query for State name." State name = Alabama? or 2?
    $states = array("2""3");
    foreach (
    $states as $numberRepresentingState => $state) {
      if (
    $state == $xcityid) {
        
    $xcityidNo $numberRepresentingState;
        break;
      }
    }
    //alabama would be 2, alaska would be 3
    // so below alabama would be 2.gif
    if (file_exists("city/" $imgid ".gif")) {
      echo 
    "<img src=\"city/" $imgid ".gif\" width=\"80\" height=\"80\" alt=\"" $xcityid " state flag\" />";
    }
    else {
      echo 
    "city/" $imgid ".gif does not exist";
    }
    ?>

    <br />
    <br />

    <?php
    /* Begin Version 5.0 */
    $homeurl buildURL("main", array(0));
    /* End Version 5.0 */
    ?>
    <a href="<?php echo $homeurl;?>">
    <img src="images/logo.gif" border="0"><br>
    </a>
    </div>

    <?php if ($demo) {?>
    <div id="demo">Demo mode.
    <a href="http://www.xzeroscripts.com/products/xzero_classifieds/buy.php">Buy it now!</a>
    </div>
    <?php }?>

    </td>

    <td align="right" valign="top">

    <div id="today">
    <?php echo QuickDate(time(), FALSE);?>
    </div>

    <?php
    $cityurl 
    buildURL("main", array($xcityid$xcityname));
    ?>
    <div id="citytitle">
    <a href="<?php echo $cityurl;?>">
    <?php echo $xcityid && !$postable_country "$xcityname, $xcountryname" $xcountryname;?>
    </a>

    </div>

    <b>

    <?php if ($xview != "main" && !$show_sidebar_always) {?>


    <!-- Begin Version 5.0 -->
    <a href="<?php echo $homeurl;?>"><?php echo $lang['HOME_LINK'];?></a>
    <!-- End Version 5.0 -->

    &nbsp;<span class="flatnavsep">&bull;</span>&nbsp;
    <a href="<?php echo $postlink;?><?php if ($syndicate) echo "target=\"_blank\"";?>><?php echo $lang['POST_LINK'];?></a>

    <?php if ($forum_dir) {?>
    &nbsp;<span class="flatnavsep">&bull;</span>&nbsp;
    <a href="<?php echo $forum_dir;?>" target="_blank"><?php echo $lang['FORUM_LINK'];?></a><?php }?>
    <?php 
    }?>

    <?php if ($demo) {?>
    &nbsp;<span class="flatnavsep">&bull;</span>&nbsp;
    <a href="admin/" target="_blank">Admin</a>
    <?php }?>

    </b>
    </td>
    </tr></table>
    Here is the header file I'm working with

  • #13
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,547
    Thanks
    57
    Thanked 148 Times in 147 Posts
    there is no reference above here

    PHP Code:
     <br />

    <?php
    // going on "$xcityid is the variable that is mysql_query for State name." State name = Alabama? or 2?
    $states = array("2""3");
    foreach (
    $states as $numberRepresentingState => $state) {
      if (
    $state == $xcityid) {
        
    $xcityidNo $numberRepresentingState;
        break;
      }
    }
    to what $xcityid is.

    To test that put

    PHP Code:
     <br />

    <?php
    $xcityidNo 
    2;
    // going on "$xcityid is the variable that is mysql_query for State name." State name = Alabama? or 2?
    $states = array("2""3");
    foreach (
    $states as $numberRepresentingState => $state) {
      if (
    $state == $xcityid) {
        
    $xcityidNo $numberRepresentingState;
        break;
      }
    }
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #14
    Regular Coder godofreality's Avatar
    Join Date
    Jan 2009
    Posts
    234
    Thanks
    1
    Thanked 15 Times in 15 Posts
    well i see a couple options here first u could just change your .gif files to be like alabama.gif and use sumthing like this which is prolly your best option
    PHP Code:
     
        
    echo "<img src=\"city/".$xcityid.".gif\" width=\"100\" height=\"100\" alt=\"".$xcityid." state flag\" />"
    or you could get overly complex with it to use sum numbers as your .gif files

    first u need to fill an array using your query

    PHP Code:
    $result mysql_query("SELECT * FROM `your_table_name`");
    $rows mysql_num_rows($result);
    $row mysql_fetch_assoc($result);
    while(
    $row)
    {
    $i 0;
    $state $row['xcityid'];
    $img[$state] = $i;
    $i++;
    $row mysql_fetch_assoc($result);
    }
    //that will fill up your array with a corresponding number and u would retrieve the image like so

    echo "<img src='" $img['alaska'] . ".gif' />";
    //each item of your array would be recalled using the state's name 
    Last edited by godofreality; 10-20-2009 at 06:18 AM.

  • #15
    New Coder
    Join Date
    May 2009
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Phil Jackson View Post
    there is no reference above here

    PHP Code:
     <br />

    <?php
    // going on "$xcityid is the variable that is mysql_query for State name." State name = Alabama? or 2?
    $states = array("2""3");
    foreach (
    $states as $numberRepresentingState => $state) {
      if (
    $state == $xcityid) {
        
    $xcityidNo $numberRepresentingState;
        break;
      }
    }
    to what $xcityid is.

    To test that put

    PHP Code:
     <br />

    <?php
    $xcityidNo 
    2;
    // going on "$xcityid is the variable that is mysql_query for State name." State name = Alabama? or 2?
    $states = array("2""3");
    foreach (
    $states as $numberRepresentingState => $state) {
      if (
    $state == $xcityid) {
        
    $xcityidNo $numberRepresentingState;
        break;
      }
    }
    Nothing changed


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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