ace2go Posted April 24, 2015 Share Posted April 24, 2015 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(); } ?> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 24, 2015 Share Posted April 24, 2015 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.