skip to Main Content

Not sure what I did wrong. I’m aware that having two fetch_assoc removes the first result but I don’t have such a thing.

$sql = "$getdb
WHERE $tablenames.$pricename LIKE 'm9%'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    echo $tableformat;
    while($row = $result->fetch_assoc()) {
    $name = str_replace('m9', 'M9 Bayonet', $row['Name']); 
    include 'filename.php';
    echo $dbtable;
}

My connect file:

$servername = "";
$username = "";
$dbname = "";
$password = "";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

require_once ('seo.php');
$dollar = '2.';
$euro = '1.9';
$tableformat = "<div class="CSSTableGenerator style="width:600px;height:150px;"><table><tr><th>Name</th><th>Price</th><th><a class="tooltips">Community<span>New !</span></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th><th>Cash Price</th><th>Trend&nbsp;&nbsp;&nbsp;&nbsp;</th><th>Picture&nbsp;&nbsp;&nbsp;</th></tr></div>";
$getdb = "SELECT utf.id, utf.PriceMin, utf.PriceMax, utf.Name, utf.Trend , community1s.price as com_price, utf.Name, utf.Trend 
FROM utf 
INNER JOIN (select id, avg(price) price from community1 group by id) as community1s 
ON utf.id=community1s.id";
$tablenames = 'utf';
$pricename = 'Name';
$idrange = range(300,380);

What happens is, it fetches the first two column’s fine and the rest of the row is not there and pushes the other results down one row, which messes up the data.

Here’s an image to demonstrate:
http://imgur.com/CQdnycW

The seo.php file is just a SEO function.

Any ideas on what may be causing this issue?

EDIT:

My Output:

echo $tableformat;
while($row = $result->fetch_assoc()) {
$name = str_replace('m9', 'M9 Bayonet', $row['Name']); 
include 'filename.php';
echo $dbtable;

EDIT: Solved it by moving my variables around. Marked as solved.

2

Answers


  1. Chosen as BEST ANSWER

    I found the issue. Some Variables that did the output were in a bad place. Rearranged them and now they are fine.


  2. Your HTML is broken, and strange things happen in broken tables. $tableformat contains HTML that opens a <div> and a <table>, but then closes the <div> with the table still open.

    Fix the broken HTML and you’ll probably find that all is well

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search