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

Link to comment
Share on other sites

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

}

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.