Jump to content

Viewing table data from GET function


ace2go

Recommended Posts

I cannot view data based upon my "wid" in the following code.  Basically I have a page that you click on a link, and it passes a number to the "wid" as an integer.  I want to call on that corresponding table that has a "like" wid.  Here is what I have so far...

<?php
    require 'database.php';
if(!empty($_GET['wid']))      { $wid = $_GET['wid'];  }
else                         { $wid = null;         }

    if ( null==$wid ) {
        header("Location: workorders.php");
    } else {
        $pdo = Database::connect();
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);    
        $sql = 'SELECT * FROM items where wid = ?';
                        $rows = $pdo->query($sql);
                        foreach ($pdo->query($sql) as $row)
                                {
                                   echo '<tr>';
                                   echo '<td>'. $row['id'] . '</td>';
                                   echo '<td>'. $row['wid'] . '</td>';
                                echo '<td>'. $row['model'] . '</td>';
                                echo '<td>'. $row['description'] . '</td>';
                                echo '<td>'. $row['cost'] . '</td>';
                                echo '<td>'. $row['retail'] . '</td>';
                                echo '<td>'. $row['tax'] . '</td>';
                                   echo '<td width=250>';
                                }                
        Database::disconnect();
    }
?>
Link to comment
Share on other sites

You said you wanted things 'like' wid but you wrote a query looking for =

 

You wrote your query statement with a substitute parm for your where clause but then you didn't prepare it and assign the parameter.

 

You ran your query and tried to process it without checking if you had any results.

 

You wrote your output to a table row but you never ended the row (nor did you begin the table). You said you wanted like, so I would expect there to be multiple rows in this html table, but you aren't prepared to handle them.

 

Fix all those things and be sure to have error checking turned on and let us know.

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.