The syntax of mysql_query in php [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
$cek=mysql_query('SELECT Header FROM CompletedHotelProjects LIMIT'.$count.', '.$count+2);
When I write this query, it fails. Can you help me, how can I write the right syntax?
Thanks...

Try this:
$cek = mysql_query(
"SELECT Header FROM CompletedHotelProjects LIMIT ".$count.", ".($count+2).";"
);

Try this :-
$new_count = $count+2;
$cek=mysql_query('SELECT Header FROM CompletedHotelProjects LIMIT $count,$new_count');

Can you please try with below query,
$countEnd = $count+2;
$cek=mysql_query('SELECT Header FROM CompletedHotelProjects LIMIT'.$count.', '.$countEnd);
i think this will help you to find a way.

Try this
$cek=mysql_query('SELECT `Header` FROM `CompletedHotelProjects` LIMIT '.$count.', '.$count+2);
EDIT:
Maybe by adding the extra braces it will.
$cek=mysql_query('SELECT `Header` FROM `CompletedHotelProjects` LIMIT '.$count.', '.($count+2));
Always use `` signs to indicate a column or table and added a space between LIMIT and the first number.

Related

How to echo value from a column using PHP? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I am new to PHP and having problems with printing values from database.
This is my code:
<?
$level = $db->Query("SELECT `level` FROM users WHERE `id` = '" . $data['id'] . "'");
$r2 = mysql_fetch_object($level);
?>
And this is what it looks like when I try to print it:
<?php
echo $r2;
?>
And when I try to echo it it doesn't print the value from level but it only loads half of the page.
I would really appreciate if someone could tell me what the problem is?
$level is a mysql result resource. Try adding the following
while ($row = $level->fetch_row()) {
var_dump($row);
}
The query is returning a result resource. You need to use that with a fetch function of some kind to retrieve the actual data. If you're using MySQLi, then you can use mysqli_fetch_row() or similar.

how can i print the mySQL sum() in php [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have this query and i am asking if i can print the result in PHP without saving the result in other table.
SELECT SUM(weekly_fees) FROM scout_cabs
You start by giving it an alias to output:
SELECT SUM(`weekly_fees`) AS `total` FROM `scout_cabs`
Then you parse it as any normal request via mysql.
<?php
$sql = "SELECT SUM(`weekly_fees`) AS `total` FROM `scout_cabs`";
$run = mysql_query($sql);
$result = mysql_fetch_assoc($run);
echo 'The sum of the query is: ' . number_format($result['total']);
It may also be worth looking into mysqli_ if you are not already using it, as mysql_ is now deprecated.

how to write this query in codeigniter, i send my id to the model, but this query must be writen good in model [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I have this query:
SELECT hapnin
FROM test.user_favourites, test.happenings t
WHERE user_id = $id
AND t.id = happening_id
I want to re-write it in a codeiniger model. Please if someone can help me with this.
You sure your query is Okay? Try this hope it works.
$this->db->select('hapnin')->from('user_favourites, happenings t')->where("user_id = $id AND t.id = happening_id", false)->get();
Try this one
$this->db->select('hapnin')
->from('user_favourites, happenings t')
->where("user_id = $id")
->where("t.id = happening_id")
->get()
->result();

select query for date between [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am doing a project where i have to fetch data of between dates plus the name of user.
The query for only date betweenis working fine but with and operater its going in wrong way so please suggest me how to implement it to achieve desired output.
this is my code:
$qry11=mysqli_query($con,"select * from entry where (create_date between '$first' and '$second') && cnor='$nme'");
so please suggest ne how to do this....any idea will be appreciate with highly gratitude.
&&
should be replaced with
AND
You seem to be already using AND in your query right
(create_date between '$first' and '$second')
use the query like below
$qry11=mysqli_query($con,"select * from entry where (create_date between '$first' and '$second') and cnor='$nme'");

Use this php code wih WHERE [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Can I use this php code wih WHERE? SELECT SUM(buzz) as buzz FROM $table I want to calculate sumation of some spesific rows.
If you want specifically in PHP then this might help you
SELECT SUM(buzz) as buzz FROM $table WHERE $where
No, you can't use PHP code in an SQL where condition. Databases typically don't include a PHP interpreter.
What you can do is use PHP to generate the where clause that you need.

Categories