Jump to content

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

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.