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.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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.
Closed 9 years ago.
Improve this question
I am getting this error where it returns Resource(25) of type (mysql_result).
All I'm doing is select something from the database and there is an item in the database.
Query:
$s2 = mysql_query("SELECT * FROM `api` ORDER BY RAND () LIMIT 1");
When I var_dump($s2) it returns this:
Resource(25) of type (mysql_result)
Any ideas?
Resource(25) of type (mysql_result) means your query is valid.
If you want to display data, you can try either of the following:
$var = mysql_fetch_array($s2);
echo $var['field_name_here'];
or
$var = mysql_result($s2, 0, 'field_name_here');
echo $var;
As suggested in the comments, you should read the manual thoroughly.
Cheers!
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.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
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 recently tried to implement this script however I have had some problems with it recently.
$q=mysql_query("select * from users where id='".$row['gamertag']."'");
while($row = mysqli_fetch_array($mw2ranks))
{
echo "<tr><td> ".$i.".";
echo "</td>
<td>$q[username]
</td>
<td>More stuff will go here</td>
<td>More stuff will go here</td>
";
$i++;
}
Then I was thinking the code $q[username] would locate the username located in the data match up. This wasn't the case, can anyone tell me why?
you need to fetch the result after querying it:
$res = mysql_fetch_assoc($q);
Note the danger of SQL-injections as mentioned in the comments. also be aware that the MySQL_* methods are deprecated. use PDO instead.
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.
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 a table here which is containing some data,So i want to copy that data and wants to print it on my webpage by the php script,So someone please help me out,If u dont mind anyone contribute the suitable code here for this question.
Use a DOM Parser like SimpleHTMLDom.
include 'simple_html_dom.php';
$html = file_get_html('http://result.msrit.edu/getresult.php?myusn=1ms10cs410&B1=GET%20RESULT');
$elems = $html->find("/html/body/table/tbody/tr[1]/th[1]/div");
foreach($elems as $v)
{
//do the parsing here
}
Read the documentation for the available options and examples.
Hope this helps!
$dom = new DomDocument();
#$dom->loadHTML(file_get_contents ('http://result.msrit.edu/getresult.php?myusn=1ms10cs410&B1=GET%20RESULT'));
$table=$dom->getElementsByTagName('table');
echo $dom->saveHTML($table->item(0));