Page 1 of 1

Php help, not displaying data?

Posted: Sat Feb 26, 2011 6:12 am
by gaogier
Hello

I am really new to php programming.

This is what I have, http://runehints.com/calculators - use gaogier to test if needed.

Ok, Now you see that here is how the mysql database is laid out.

Main database
ID - Name - Members - tablename

Calculator databases
craftingcalc
fishcalc
firecalc
miningcalc
prayercalc
woodcalc
agilitycalc
herbcalc
cookcalc
fletchingcalc
thievingcalc
magiccalc
farmingcalc


As you can see, its not set out very well.

When I go to add data to the farmingcalc, I need to access the farming database only. Accessed by the ID.

However it dose not display the data, so I can't even add the edit or even add new data to the database yet.

Why dose it not work? What have I missed?

Code: Select all

    /* RuneHints CMS */
    /* Achievement Edit Submit */
    /* Achievement Edit Form */
    /* Achievement Add Submit */
    /* Achievement Add Form */
    /* Achievement Echo Records */   
    if (($admin == 'calculator') && ($_POST['edit'])) {
        $updated = time();
            $sql = "UPDATE `calc` SET
            `name` = '{$_POST['name']}',
            WHERE `id` = '{$id}'";
            $result = $db->query($sql);
            
            echo '<div class="msgOk"><span>Updated</span>Record was updated successfully.</div>';
    }
     
    if (($admin == 'calculator') && (!empty($id))) {
            $sql = "SELECT * FROM calc WHERE `id` = '{$id}'";
            $result = $db->query($sql);

            while ($row = $db->fetch($result)) {
			$calc_tablename = $row['tablename'];
            $query="SELECT * FROM $calc_tablename";

            echo '<p>
                   
                            <table class="guide">
                        <tr class="trtitle">
                                    <th>Item</td>
                                    <th>Level</td>
                                    <th>Xp</td>
                                    <th>Members</td>
                                    <th>Edit</td>
                                </tr>';

while($row = mysql_fetch_array($result))
{

			$item = $row['item'];
			$level = $row['level'];
			$xp = $row['xp'];
			$mem = $row['members'];

                    echo '<tr style="border-bottom: 1px solid #a07c3c;">
                                    <td><a>'.$item.'</a></td>
                                    <td><a>'.$level.'</a></td>
                                    <td><a>'.$xp.'</a></td>
                                    <td><a>'.$mem.'</a></td>
                                    <td><a href="item/edit/'.$row[item].'"><img src="/images/edit.png" border="0" alt="Edit"></td>
                                </tr>';
                             }
                                 echo '<tr>
                                    <td></td>
                                    <td></td>
                                </tr>
                            </table>
                   
          </p>';
          }
    } elseif (($admin == 'calculator') && (empty($id))) {
            $sql = "SELECT * FROM calc";
            $result = $db->query($sql);
            echo '<table class="guide">
                        <tr class="trtitle">
                            <th>Calculator Name</td>
                            <th align="center">Edit items</td>
                            <th align="center">Delete</td>
                        </tr>';
            while ($row = $db->fetch($result)) {
                    echo '<tr style="border-bottom: 1px solid #a07c3c;">
                            <td width="80%"><a>'.$row[name].'</a></td>
                            <td width="10%" align="center"><a href="edit/'.$row[id].'"><img src="/images/edit.png" border="0" alt="Edit"></a></td>
                            <td width="10%" align="center"><a href="delete/'.$row[id].'"><img src="/images/error.png" border="0" alt="Delete"></a></td>
                        </tr>';
            }
            echo '</table>';
    }
?>

Re: Php help, not displaying data?

Posted: Sun Feb 27, 2011 12:11 am
by social_experiment

Code: Select all

if (($admin == 'calculator') && (!empty($id))) {
            // 1
            $sql = "SELECT * FROM calc WHERE `id` = '{$id}'";
            $result = $db->query($sql) or die(mysql_error());

            while ($row = $db->fetch($result)) {
                        $calc_tablename = $row['tablename'];
            // 2
            $query="SELECT * FROM $calc_tablename";

            echo '<p>
You can check if you have error's in your SQL syntax by adding 'or die()' like i did. (I don't know what error check is already in your function so it there is).
From which SELECT statement are you trying to display ( 1 or 2)?

Code: Select all

$row[item]
// should be this, you got it right in the first part where you 
// assign value to the variables.
$row['item']