Jump to content

MySQL Query not working with PHP?


fishbaitfood

Recommended Posts

Hi there,

 

I have this query, which outputs the records properly in PhpMyAdmin.

But when using this query inside my PHP code, the result is incomplete.

Instead of retrieving the expected 15 results, I only get the first one twice.

Also, I don't get any errors.

 

<?php
$get_files = "SELECT `id` FROM `files` WHERE `category` = 'W';";

include_once('connection.inc.php');
$con = mysql_connect(MYSQL_SERVER, MYSQL_USERNAME, MYSQL_PASSWORD) or die ("Connection failed: " . mysql_error());
$dbname = "myDB";
$select_db = mysql_select_db($dbname, $con) or die ("Can't open database: " . mysql_error());

$result_files = mysql_query($get_files) or die ("Query failed: " . mysql_error());
$files = mysql_fetch_array($result_files);
$W_files = "'".implode("', '", $files)."'";

// echo $W_files;	outputs the first number twice, instead of the expected 15 different ones

$get_checklist = "SELECT * FROM `checklist` WHERE `id` IN ($W_files) ORDER BY `id` ASC;";
$result_checklist = mysql_query($get_checklist) or die ("Query failed: " . mysql_error());

// .... code for displaying
?>

Link to comment
https://forums.phpfreaks.com/topic/253478-mysql-query-not-working-with-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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