Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
<?php
function username($uuid) {
$username = file_get_contents("https://us.mc-api.net/v3/name/$uuid/json");
$data = json_decode($username, true);
return $data['name'];
}
while( $row = mysql_fetch_assoc( $result ) ){
$uuid = $row['UUID'];
$kills = $row['KILLS'];
$deaths = $row['DEATHS'];
echo
"<tr>
<td>
<img src='http://cravatar.eu/head/$uuid/64.png'/>
" . username($uuid) . "
<td>$kills</td>
<td>$deaths</td>
</tr>\n";
}
I've recently started learning php for the sake of web leaderboards. I've gotten a working version, although this part is stumping me.
I'm trying to get it after the avatar is displayed it also displays the username that's hooked onto the uuid. The avatar works just not the username section.
Here's a preview of this code: https://gyazo.com/de6f92aa637c0f43f560e4ddfb986a0d
I've googled some common issues but I cannot find anything. Any help would be appreciated.
you're not closing the <td> that is opened at the start of the row. should it be:
<td>
<img src='http://cravatar.eu/head/$uuid/64.png'/>
" . username($uuid) . "</td>
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
hey guys i am stuck at very end point of my code , my aim was to Store image path to database and store the image to a directory. and than i want to show those images.
i am successfully done uploading part but now i am stuck how can i show those images on my webpage, here is my code
<?php
$sql = "SELECT * FROM pictures";
$result = mysqli_query($conn, $sql);
$data = mysqli_fetch_array($result,MYSQLI_ASSOC);
while($row = mysqli_fetch_array($result))
{
$image_path=$row["folder_name"];
$image_name=$row["picture_name"];
echo "img src=".$image_path."/".$image_name." width=100 height=100";
}
?>
If you want to fetch associative arrays, use fetch_assoc instead, your $data is not needed here, it's simpler at the end. Also, only select the fields you need in your query. To fix your problem, You are simply missing the HTML , try this:
<?php
$sql = "SELECT folder_name, picture_name FROM pictures";
$result = mysqli_query($conn, $sql);
if(!$result) {
die("Error with your Query: " . mysqli_error($conn));
}
while($row = mysqli_fetch_assoc($result)) {
$image_path = $row["folder_name"];
$image_name = $row["picture_name"];
echo "<img src=\"" . $image_path . "/" . $image_name . "\" width=\"100\" height=\"100\"></img>\n";
}
?>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
So I have the following query to show all users from my database:
<ul class="names">
<table>
<tr>
<th>Navn</th>
<th>Email</th>
<th>Score</th>
</tr>
<?php
$connection = mysql_connect('localhost', 'users', 'password'); //The Blank string is the password
mysql_select_db('users');
$query = ("SELECT * FROM oneusers"); //You don't need a ; like you do in SQL
$result = mysql_query($query);
$row=mysql_fetch_array($result);
while($row = mysql_fetch_array($result)){ //Creates a loop to loop through results
echo "<tr><td>" . $row['iUserName'] . "</td><td>" . $row['iUserEmail'] . "</td><td>" . $row['iUserCash'] . " DKK</td></tr>"; //$row['index'] the index here is a field name
}
mysql_close(); //Make sure to close out the database connection
?>
</table>
</ul>
But for some reason it doesnt show all the data.
In only shows the user with iUserId 2 and not one.
Does anyone have an idea of what might be wrong?
I can log in with iUserId 1's credentials, and it shows fine the info on the login page.
But not here :S
Remove line $row = mysql_fetch_array($result);
Because this line starts to fetching records from your query results. First fetched record is record with id 1 and you do nothing with it.
Then you start echoing other records, but record with id 1 is already skipped.
You fetch the first row before your while loop is defined; once you enter the while loop it fetches the next row, which is the second. Remove the first mysql_fetch_array($result) operation.
Incidentally, also, the original mysql api in PHP is deprecated, it is recommended to use mysqli instead.
I think you should put it this way though
<?php
$connection = mysql_connect('localhost', 'users', 'password'); //The Blank string is the password
mysql_select_db('users');
let all the connection be outside the "ul" tag.
$query = ("SELECT * FROM oneusers"); //You don't need a ; like you do in SQL
$result = mysql_query($query);
$query = ("SELECT * FROM oneusers"); //You don't need a ; like you do in SQL
$result = mysql_query($query);
$row=mysql_fetch_array($result);
?>
<ul class="names">
<table>
<tr>
<th>Navn</th>
<th>Email</th>
<th>Score</th>
</tr>
<?php
while($row){ //Creates a loop to loop through results
echo "<tr><td>" . $row['iUserName'] . "</td><td>" . $row['iUserEmail'] . "</td><td>" . $row['iUserCash'] . " DKK</td></tr>"; //$row['index'] the index here is a field name
}
mysql_close(); //Make sure to close out the database connection
?>
</table>
</ul>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
My search is running perfectly but I need to link each result to a description page. Any ideas as to how to do it?
<?php
session_start();
require_once 'login.php';
$conn = mysqli_connect($server,$user,$password,$dbase);
if(!$conn){
die("Failure to connect".mysqli_connect_error());
}
$id = $_SESSION['twitcher'];
$srch = $_POST['searchstr'];
$sql = "select * from gallery where title like '%$srch%'";
$result = mysqli_query($conn,$sql);
if(mysqli_num_rows($result) > 0){
while ($rows=mysqli_fetch_assoc($result)){
echo $rows['title'].$br.$br;
}
}else echo "No posts found.";
mysqli_close($conn);
?>
Exactly as #Dagon stated: You need to simply echo out a link tag (<a>)
while ($rows=mysqli_fetch_assoc($result)) {
echo "<a href='/link_to_where_you_want_to_go'>" . $rows['title'] . "</a>" . $br . $br;
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
im trying to create a drop down many and populate the options from fields in a database that i have.
So far i have got the following code:
<?php
session_start();
include_once("config.php");
$query = "SELECT Category FROM books";
$result = mysqli_query ($mysqli, $query);
echo "<select name=dropdown value=''>Dropdown</option>";
while($row = mysqli_fetch_array($result))
{
echo "<option value=$row[Category]>$row[Category]</option>";
}
echo "</select>";
?>
</div>
</body>
</html>
However when i try to view the page nothing seems to happen.
My page remains blank and all i see is the color that i gave to the body in the css file.
Was wondering if anyone knew wh this was happening and if they can sort it out?
Thanks!
Assuming you are getting results from your query. Can find out by print_r($result). Think you are getting death screen because of quotes and missing opening for first option in dropdown.
echo '<select name="dropdown" value=""><option value="">Dropdown</option>';
while($row = mysqli_fetch_array($result))
{
echo '<option value="' . $row['Category'] . '">' . $row['Category'] . '"</option>';
}
echo "</select>";
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I cannot figure out how to get my code to create a new HTML column for results, in my table, in a while ($row = mysql_fetch_array($result)) { - when the results returned reach 10, I want a new table column to be created in the same HTML table.
How can I do this? The code I'm using is:
while ($row = mysql_fetch_array
($result, MYSQL_ASSOC)) {
$row_color = ($row_count % 2) ? $color1 : $color2;
echo '<tr><td align="left" bgcolor=' . $row_color . '> <b>' . $row['manufacturer'] . '</b>: <a href=view_inventory.php?mdl_key=' . $row['mdl_key'] . '&man_key=' . $row['man_key'] . '&cls_key=' . $row['cls_key'] . '&sub_cls_key=' . $row['sub_cls_key'] . '> ' . $row['model'] . '</a></b></td></tr>';
$row_count++;
}
You should really use the new PDO interface as the mysql extension is deprecated long ago, read this documentation if you have a choice.
Still, with the old extension, simply do this:
$rowCount = mysql_num_rows($result);
if ($rowCount >= 10) {
while ($row = mysql_fetch_array($result)) {
// Do your extra column stuff here.
}
}
else {
while ($row = mysql_fetch_array($result)) {
// Do your normal stuff here.
}
}
// It is a good practise to remove variables after
// loops, this helps releasing memory in large scripts.
unset($rowCount, $row, $result);