-2

What i have:

$table_name_arcticles = 'arcticles';
$arcticles_count = mysqli_query($connection, "SELECT * FROM `articles` WHERE `categories_id` ="  . $data['id']);

What i need, something like this:

$table_name_arcticles = 'arcticles';
$arcticles_count = mysqli_query($connection, "SELECT * FROM $table_name_arcticles WHERE `categories_id` ="  . $data['id']);
  • 2
    so what's the problem? – Funk Forty Niner Jun 01 '17 at 17:51
  • 1
    This should work...? – Daniel Jun 01 '17 at 17:52
  • btw, the word is "articles" and not "arcticles". I doubt that's a word in any language. So again: *"what's the problem?"* - You didn't say, so I for one cannot guess and as to where you're pre-querying from with `$data['id']`. – Funk Forty Niner Jun 01 '17 at 17:55
  • I'm on the fence to follow the "unclear" vote to close so far, as there stands to be a duplicate for this. If you're not going to tell us what's "not working", then wait longer and don't make "us" wait neither. You're not only wasting other people's time, but yours also. So use `mysqli_error($connection)` on the query then come back and tell us what that error was. If you left the question, then that doesn't help you at all. – Funk Forty Niner Jun 01 '17 at 17:58
  • @Fred-ii- arcticles is what I call ice cubes in a language I just made up. – Don't Panic Jun 01 '17 at 18:01
  • 1
    @Don'tPanic Funny you should say that, I had that very same thought *lol!* GMTA ;-) – Funk Forty Niner Jun 01 '17 at 18:02
  • [Little Bobby](http://bobby-tables.com/) says ***[your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)*** Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php). Even [escaping the string](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) is not safe! – Jay Blanchard Jun 01 '17 at 18:37
  • i found Answer: $arcticles_count = mysqli_query($connection, "SELECT COUNT(`id`) AS 'total_count' FROM ` $table_name_articles` WHERE ` categories_id` =" . $data['id']); – romanPotapskyi Jun 01 '17 at 20:53

1 Answers1

0

use this...

$table_name_arcticles = 'arcticles';
$query="SELECT * FROM ".$table_name_arcticles." WHERE `categories_id` ="  . $data['id'];
$arcticles_count = mysqli_query($connection,$query);
zarif khan
  • 81
  • 6
  • Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in – romanPotapskyi Jun 01 '17 at 18:18
  • Turn the tide against teaching/propagating sloppy and dangerous coding practices. If you post an answer without prepared statements [you may want to consider this before posting](http://meta.stackoverflow.com/q/344703/). Additionally [a more valuable answer comes from showing the OP the right method](https://meta.stackoverflow.com/a/290789/1011527). – Jay Blanchard Jun 01 '17 at 18:37
  • how you know that it is not working. when you know then please give answer. – zarif khan Jun 01 '17 at 19:04
  • please show below code after $articale_count variable then i will fix that. problem is coming after that. – zarif khan Jun 01 '17 at 19:08
  • You are getting error in mysqli_fetch_assoc(), not from above code, update the code – Rajesh Pradhan Jun 01 '17 at 19:25