...

View Full Version : mysql_query for State flag



djdubuque
10-19-2009, 06:56 PM
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.

Phil Jackson
10-19-2009, 07:12 PM
try



<?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\" />";
}
?>

djdubuque
10-19-2009, 07:20 PM
try



<?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.

Phil Jackson
10-19-2009, 07:24 PM
then create a new row in database, say imgId 001, 002, 003



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


should output


<img src="city/001.gif" width="100" height="100" alt="Alabam state flag" />

djdubuque
10-19-2009, 07:32 PM
then create a new row in database, say imgId 001, 002, 003



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


should output


<img src="city/001.gif" width="100" height="100" alt="Alabam state flag" />

What would the settings be in the dB? VAR?

Phil Jackson
10-19-2009, 07:45 PM
just use text or var its only to stick a lil somet in, int will do.

djdubuque
10-19-2009, 07:50 PM
Code has been installed but no image shows.

Phil Jackson
10-19-2009, 08:31 PM
right click view source paste me the bit about the image.

Phil Jackson
10-19-2009, 08:32 PM
and change this to:



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";
}
?>

djdubuque
10-19-2009, 08:39 PM
and change this to:



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

Phil Jackson
10-19-2009, 09:17 PM
i need to see more of your code.


$imgId has no value

djdubuque
10-20-2009, 12:33 AM
<?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 > 0 && !$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

Phil Jackson
10-20-2009, 05:36 AM
there is no reference above here



<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



<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;
}
}

godofreality
10-20-2009, 06:15 AM
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



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



$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

djdubuque
10-20-2009, 01:39 PM
there is no reference above here



<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



<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

djdubuque
10-20-2009, 01:45 PM
Will this help you more?


<?php

require_once("initvars.inc.php");
require_once("config.inc.php");

?>
<table width="100%"><tr><td valign="top">
<?php

// Show city list

if($location_sort)
{
$sort1 = "ORDER BY countryname";
$sort2 = "ORDER BY cityname";
}
else
{
$sort1 = "ORDER BY c.pos";
$sort2 = "ORDER BY ct.pos";
}

if ($show_region_adcount || $show_city_adcount)
{
// First get ads per city and country
$country_adcounts = array();
$city_adcounts = array();
$sql = "SELECT ct.cityid, c.countryid, COUNT(*) as adcnt
FROM $t_ads a
INNER JOIN $t_cities ct ON ct.cityid = a.cityid AND ($visibility_condn)
INNER JOIN $t_countries c ON ct.countryid = c.countryid
WHERE ct.enabled = '1' AND c.enabled = '1'
GROUP BY ct.cityid";

$res = mysql_query($sql) or die(mysql_error().$sql);

while($row=mysql_fetch_array($res))
{
$country_adcounts[$row['countryid']] += $row['adcnt'];
$city_adcounts[$row['cityid']] += $row['adcnt'];
}
}

$sql = "SELECT * FROM $t_countries c INNER JOIN $t_cities ct ON c.countryid = ct.countryid AND ct.enabled = '1' WHERE c.enabled = '1' GROUP BY c.countryid $sort1";
$resc = mysql_query($sql);

$country_count = mysql_num_rows($resc);
//$split_at = ($country_count%3?((int)($country_count/3))+2:($country_count/3)+1);
$percol = floor($country_count/$location_cols);
$percolA = array();
for($i=1;$i<=$location_cols;$i++) $percolA[$i]=$percol+($i<=$country_count%$location_cols?1:0);

$i = 0; $j = 0;
$col = 1;
while($country = mysql_fetch_array($resc))
{
/* Begin Version 5.0 */
$country_url = buildURL("main", array((0-$country['countryid']), $country['countryname']));
/* End Version 5.0 */
?>


<div><a href="<?php echo $country_url; ?>" class="citylist_country"><?php echo $country['countryname']; ?> <?php if($show_region_adcount) echo "(".(0+$country_adcounts[$country['countryid']]).")"; ?></a></div>


<?php

if($country['countryid'] == $xcountryid || !$expand_current_region_only)
{

$sql = "SELECT * FROM $t_cities ct WHERE countryid = $country[countryid] AND enabled = '1' $sort2";
$resct = mysql_query($sql);

/* Begin Version 5.0 */
$citycount = mysql_num_rows($resct);
/* End Version 5.0 */

while($city=mysql_fetch_array($resct))
{
/* Begin Version 5.0 */
if ($shortcut_regions && $citycount == 1
&& $city['cityname'] == $country['countryname']) {
continue;
}

$city_url = buildURL("main", array($city['cityid'], $city['cityname']));
/* End Version 5.0 */

?>

<a href="<?php echo $city_url; ?>" class="citylist_city"><?php echo $city['cityname']; ?> <?php if($show_city_adcount) echo "(".(0+$city_adcounts[$city['cityid']]).")"; ?></a><br>

<?php

}
}

?>


<?php

$i++; $j++;
//if($i%$split_at == 0) echo "</td><td valign=\"top\">";
if ($j%$percolA[$col]==0 && $i<$country_count) { echo "</td><td valign=\"top\">"; $col++; $j=0; }

}


?>

</tr></td></table>

djdubuque
10-22-2009, 05:49 PM
Looks like I was abandoned. No more help?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum