Hello There Iam Sorry My problem Will take Time To Explain So Iam Sorry For That

first thing that's my code in the index file

<?php
$result = mysql_query("SELECT * FROM games");
while($row = mysql_fetch_array($result))
{
echo "Game Name : <a href='GameDetails.php?id=$row[id]'>$row[name]</a><br/>";
echo "Genre : $row[genre]<br/>";
}
?>

In The Past I Was Using This Code In The Add Game Form

<form name='vbform' method="post" action="Game_Insert.php">
Game Name : <input type="text" name="name" size="50" maxlength="150" />
Genre :
<select size="1" name="genre">
<OPTION value="Action">Action</OPTION>
<OPTION value="Rpg">Rpg</OPTION>
<OPTION value="Strategy">Strategy</OPTION>
</select>

Everything Was Ok And Cool

But I Was In Need Of A Search Page That Get All games Under This Genre

So I Made The Genre Dynamic (( Like The Sections ))

Now My Code In The Add For Look Like This

Genre : <select size="1" name="genre">
<?php
include("config.php");
$sql = mysql_query ("SELECT * FROM genre order by id ASC") or die ("error");
while($genre=mysql_fetch_array($sql))
{
echo "<OPTION value='$genre[id]'>$genre[name]</OPTION>";
}
?>
</select>

Now Its Insert The Id Of The Genre In The Database Instead Of The Name Of The Genre

The Images Will Explain More

Here It Show ID ( 1 ) Instead Of ( Action )

http://www.daniweb.com/forums/attachment.php?attachmentid=22647&stc=1&d=1319151363

http://www.daniweb.com/forums/attachment.php?attachmentid=22648&stc=1&d=1319151363

All I Need Now Is To make My First Code Show The Genre Name In Index File

Instead Of The Id Of The File :(

Iam Very Sorry For My Bad English

I Forget To Say

Genre Now In Separate Table And Have Its Own ID , Name

Zero,

while($genre=mysql_fetch_array($sql))
{
echo "<OPTION value='$genre[id]'>$genre[name]</OPTION>";
}

This should be changed to:

while($genre=mysql_fetch_array($sql))
{
echo "<OPTION value='$genre[name]'>$genre[name]</OPTION>";
}

The <option> tag takes the value (which you currently have as genre[id]. Hope I understood you correctly.

Zero,

while($genre=mysql_fetch_array($sql))
{
echo "<OPTION value='$genre[id]'>$genre[name]</OPTION>";
}

This should be changed to:

while($genre=mysql_fetch_array($sql))
{
echo "<OPTION value='$genre[name]'>$genre[name]</OPTION>";
}

The <option> tag takes the value (which you currently have as genre[id]. Hope I understood you correctly.

Yeah You Understood Me

But Iam Gonna Make

Genre.php?id=$id

Is This Will be Possible With Your Changes Of Code ??

Coz I Made The Genre In Separate Table

I would need to see more of your code to see if it would work.

It is not a good idea to use 2 separate tables though. You really do not need to use a table for the "genre". Many of those games are going to fall into more then one category, which your current system is not going to support.

See

I Was Using This Code In The Add Form

Add.Php

<form name='vbform' method="post" action="ins_ads.php">
Ads Title : <input type="text" name="title" size="37" maxlength="30" />

Section : <select size="1" name="cat">
<?php
include("config.php");
$sql = mysql_query ("SELECT id,name FROM ads_cat order by id desc") or die ("error");
while($cat=mysql_fetch_array($sql))
{
echo "<OPTION value='$cat[id]'>$cat[name]</OPTION>";
}
?>
</select>
</form>

Index.php

<?php
$result = mysql_query("SELECT * FROM ads");
while($row = mysql_fetch_array($result))
{
echo "$row[name]':
}
?>

Cat.php (( Section File ))

<?php
include('./config.php');
$id = intval($_GET["id"]);

$result = mysql_query("SELECT * FROM ads WHERE cat='$id'");

?>

The Code In Red Thats What I Need To Use On My Coding Now

The Site Iam Coding

Show All Information In Index Page

But The Old Site That I Write The Code Below Show Only The Name In The Index File

I Hope I Explained What I Need :(

Iam using The (( ID )) In The First Post To Make A

Genre.php File That Contain A Code Like This

$result = mysql_query("SELECT * FROM games WHERE genre='$id'");

So It Retrive Every Game That Have This Genre

Thats Why I Insert Id In Database Instead Of The Name

Ok, this makes a little more sense now.

Post your code for the "ins_ads.php" page. What you will want to do is after the person submits (adds a game), you will retrieve the ID, then you will do a mysql_query to get the name of the genre based off the ID that was retrieved.

I will show you the proper code if this english does not make sense.

Ok, this makes a little more sense now.

Post your code for the "ins_ads.php" page. What you will want to do is after the person submits (adds a game), you will retrieve the ID, then you will do a mysql_query to get the name of the genre based off the ID that was retrieved.

I will show you the proper code if this english does not make sense.

You Got What I Need :)

I Will Post You The Codes

I Deleted Some Codes So The Code Wont Be Long I Left The Important

This Is Add_Game.php

<form name='vbform' method="post" action="Game_Insert.php">

Game Name <input type="text" name="name" size="50" maxlength="150" />
<br/><br/>
Poster <input type="text" name="poster" size="50" maxlength="150" />
<br/><br/>
Old Price <input type="text" name="oldprice" size="50" maxlength="50" />
<br/><br/>
New Price <input type="text" name="newprice" size="50" maxlength="50" />
<br/><br/>
Video <input type="text" name="video" size="50" maxlength="150" />
<br/><br/>

Genre : <select size="1" name="genre">
<?php
include("config.php");
$sql = mysql_query ("SELECT * FROM genre order by id ASC") or die ("error");
while($genre=mysql_fetch_array($sql))
{
echo "<OPTION value='$genre[id]'>$genre[name]</OPTION>";
}
?>
</select>

<p class="submit"><input type="submit" value="Add Game" /></p>

</form>

Game_Insert.Php

<?php

include('config.php');

$d = date("d");
$m = date("m");
$y = date("Y");
$Xdate = "$d/$m/$y";

$name      = addslashes($_POST['name']);
$poster   = addslashes($_POST['poster']);
$genre   = addslashes($_POST['genre']);
$console   = addslashes($_POST['console']);
$company   = addslashes($_POST['company']);
$oldprice     = addslashes($_POST['oldprice']);
$newprice    = addslashes($_POST['newprice']);
$status    = addslashes($_POST['status']);
$copies    = addslashes($_POST['copies']);
$details    = addslashes($_POST['details']);
$video    = addslashes($_POST['video']);
$link    = addslashes($_POST['link']);
$rate    = addslashes($_POST['rate']);

if ($name == ""){
echo "<div align='center'>You Must Fill All Fields<a href='javascript:history.back(1)'>( Back )</a></div>";
}else{
$query = @mysql_query ("INSERT INTO games (name,poster,genre,console,company,oldprice,newprice,status,copies,details,video,link,rate,date) VALUES ('$name','$poster','$genre','$console','$company','$oldprice','$newprice','$status','$copies','$details','$video','$link','$rate','$Xdate')") or die ("Error");
echo "<p align=center>Game Added ..</p>";
echo "<META HTTP-EQUIV='refresh' CONTENT='1; URL=Game_Add.php'>";
}

?>

Index.php

<?php

$result = mysql_query("SELECT * FROM games");
while($row = mysql_fetch_array($result))
  {
echo "Game Name : <a href='GameDetails.php?id=$row[id]'>$row[name]</a><br/>";
echo " Game Genre : $row[genre]<br/>";
}
?>

The Index File Now Show The Id Of The genre Instead Of The Name

My comments are in the code. Hope this helps!

game_insert.php

<?php
     //game_insert.php
    include('config.php');
     
    $d = date("d");
    $m = date("m");
    $y = date("Y");
    $Xdate = "$d/$m/$y";
     
    $name = addslashes($_POST['name']);
    $poster = addslashes($_POST['poster']);
    $genre = addslashes($_POST['genre']);
    $console = addslashes($_POST['console']);
    $company = addslashes($_POST['company']);
    $oldprice = addslashes($_POST['oldprice']);
    $newprice = addslashes($_POST['newprice']);
    $status = addslashes($_POST['status']);
    $copies = addslashes($_POST['copies']);
    $details = addslashes($_POST['details']);
    $video = addslashes($_POST['video']);
    $link = addslashes($_POST['link']);
    $rate = addslashes($_POST['rate']);
       
       //find the name of the genre
          $sql = "SELECT name FROM genre WHERE id = '$genre'";
           $result = mysql_query($sql);
             while($genre_name = mysql_fetch_array($result)) {
                $genre = $genre_name['name'];
              }
            //the above code should produce the genre name based off the id
 
    if ($name == ""){
    echo "<div align='center'>You Must Fill All Fields<a href='javascript:history.back(1)'>( Back )</a></div>";
    }else{
    $query = @mysql_query ("INSERT INTO games (name,poster,genre,console,company,oldprice,newprice,status,copies,details,video,link,rate,date) VALUES ('$name','$poster','$genre','$console','$company','$oldprice','$newprice','$status','$copies','$details','$video','$link','$rate','$Xdate')") or die ("Error");
    echo "<p align=center>Game Added ..</p>";
    echo "<META HTTP-EQUIV='refresh' CONTENT='1; URL=Game_Add.php'>";
    }
     
    ?>

Thanks So Much For Your help

you Mean After Your Code I will Still use this code

$result = mysql_query("SELECT * FROM games WHERE genre='$id'");

in the Genre.php Page ?

I Used The Code Its Ok It Insert The Name Of Genre In Database Not The (( ID ))

So When I Going To make The Page That Got All The Games Of This genre

Genre.php?id=$id

<?php
include('./config.php');
$id = intval($_GET["id"]);
$result = mysql_query("SELECT * FROM games WHERE genre='$id'");
?>

It Will Not Work Right ?

What does your genre.php code look like? Instead of ID, you can search by name... (SELECT * FROM games WHERE genre = '$genre_name')

My above code will store the genre as the genre name (not the genre id) in your games table.

Ok I Will Show You My Function Code And Tell me Is Your Code

(SELECT * FROM games WHERE genre = '$genre_name')

Will Do What I need Or No

I Made This Function

function genre()
{

$Sql = mysql_query("SELECT id,name FROM genre order by order_cat");
$cats = mysql_num_rows($Sql);

while ($Row = @mysql_fetch_array($Sql))
{
$rows .= "<a href='Genre.php?id=$Row[id]'>$Row[name]</a><br/>";
}

@mysql_free_result($sql);

return $rows;
}

And In The Index File

<?php
include('Function.php');
$headers = headers("templates/status.html");
$headers = str_replace("{status}",status(),$headers);

echo $headers;

?>

Status.html

Contain This

{status}

It Show Genres In The Main Page

Action
Rpg
Strategy

Now Can I Use Your Method To Get All Games Genre In The

Genre.php Page With This Code ?

(SELECT * FROM games WHERE genre = '$genre_name')

Like I said before, what does your genre.php code look like? Not exactly sure what the "problem" you're having is anymore.

Like I said before, what does your genre.php code look like? Not exactly sure what the "problem" you're having is anymore.

In The Index Page Every Genre Has An ID

<a href='Genre.php?id=$Row[id]'>$Row[name]</a>

When I Click On It It Show genre.php Page

It Will Have This Code

<?php
include('Admin/config.php');
$id = intval($_GET["id"]);
("SELECT * FROM games WHERE genre='$id'");
?>

If You have Better Code Or Way With My Function I Will Be Very Happy

And Sorry Coz i Wasted Your Time

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.