Jump to content

[SOLVED] Going Insane Here - Help Please


widget

Recommended Posts

Using php and mySQL

 

Table consists of

 

user_name

amulet_id

 

What I am trying to do is display a table of 9 cells (3 by 3) kinda like a puzzle.

Labeled 1 to 9

 

If the user has a puzzle piece, it shows in the table.

 

example, if they have piece number 9 then in the database would be...

 

user_name: pinkkitty

amulet_id: 9

 

Here is my code

 

$amulet_piece = mysql_query("SELECT * FROM amulet WHERE user_name = $username");

if ($amulet_piece[amulet_id] = 1)
{
$amulet1 = "<img src=$base_url/images/real image here.gif>";
}
else
{
$amulet1 = "<a href=amulet.pro.php?amulet=1><img src=$base_url/faded image here.gif></a>";
}

if ($amulet_piece[amulet_id] = 2)
{
$amulet2 = "<img src=$base_url/images/real image here.gif>";
}
else
{
$amulet2 = "<a href=amulet.pro.php?amulet=2><img src=$base_url/faded image here.gif>";
}

 

I have tried all sorts of combination's and I cant get it to work correctly, any help is greatly appreciated.

 

I just know theres probably an easier way to accomplish what I am doing.

 

Link to comment
https://forums.phpfreaks.com/topic/134014-solved-going-insane-here-help-please/
Share on other sites

Also I've just noticed you need to use a double equals on your if statement otherwise you are assigning that value not validating it. This would also return as true.

 

$amulet_piece = mysql_query("SELECT * FROM amulet WHERE user_name = $username");

if ($amulet_piece[amulet_id] == 1)
{
$amulet1 = "<img src=$base_url/images/real image here.gif>";
}
else
{
$amulet1 = "<a href=amulet.pro.php?amulet=1><img src=$base_url/faded image here.gif></a>";
}

$amuletQuery = mysql_query("SELECT * FROM amulet WHERE user_name = $username");

while ($amulet_piece = mysql_fetch_array($amuletQuery))
{

if ($amulet_piece[amulet_id] == 1)
{
$amulet1 = "<img src=$base_url/images/user_images/opg_1/items/item_30893.gif>";
}
else
{
$amulet1 = "<a href=amulet.pro.php?amulet=1><img src=$base_url/farm/images/1.gif></a>";
}

}

This is a textbook example of this type of query:

 


<?php
mysql_connect("localhost", "mysql_user", "mysql_password") or
    die("Could not connect: " . mysql_error());
mysql_select_db("mydb");

$result = mysql_query("SELECT id, name FROM mytable");

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    printf("ID: %s  Name: %s", $row["id"], $row["name"]);
}

mysql_free_result($result);
?>



 

You might want to try tweaking this script and see what outputs.

 

Did you try single quotes?

 

Also try this:

 

$link = mysql_connect("localhost", "mysql_user", "mysql_password");

mysql_select_db("db_name", $link);
$amuletQuery = mysql_query("SELECT id, name FROM mytable",$link);
echo mysql_errno($link) . ": " . mysql_error($link) . "\n";

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.