How to display row from page ID [closed] - php

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 9 years ago.
Improve this question
I am very new and trying to get from the url ie
device.php?id=2
and use the id number multiple times.
can anyone tell me how to display this?
Thanks in advance

1) Get the ID.
$id = $_GET["id"];
2) Search for $id in your database, using MySQL functions like mysqli_fetch_array() etc.
3) Echo the values you fetched, using simple HTML and PHP.

$id = $_GET['id'];
$sql= mysql_query("select * from tableName where id = $id ");
while($row = mysql_fetch_array($sql))
{
echo $row['columnName'];
}

The variable should be in $_GET["id"].

<?php
echo $_GET['id'];
?>

Related

I am trying to get the user id which is created automatically [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
$sql4 = "SELECT userid, userName FROM $user_table WHERE userName= '$userNames'";
$result = $conn->query($sql4);
$_SESSION['myUser'] = $result['userid'] ;
I have most code I can find but nothing works
Assuming these lines of code come immediately after executing an insert of a new user record and you are using PDO. You could try:
$last_id = $conn->lastInsertId();
$_SESSION['myUser'] = $last_id;

is it possible to load unique item or one of a kind item from sql using php? (check image) [closed]

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
The image above is my sql database. what I want to do is load the names and echo in json but the thing is though, I want to show one of each name. Like see how there are 4 assassinshadow entries? I want php to echo only one of em. not making much sense am I? haha
You can use DISTINCT in your mysql query:
$mysqli = mysqli_connect("example.com", "user", "password", "database");
$query = "SELECT DISTINCT name from yourtable";
$res = mysqli_query($mysqli, $query);
$row = mysqli_fetch_assoc($res);
Two ways to do that:
SELECT distinct name FROM my_table
or
SELECT name FROM my_table group by name

Making posts,getting data from mysql table [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
how i can make example: post.php and when somebody goes to post.php to show all posts and when somebody click on one post to show in URL post.php?id=1(id=1 by id in database? and when it types post.php?id=2 to go to id 2 in database and show all datas from row of table by id 2)
Use the $_GET method to pass the url. At the top of the php file you can access the information posted in the url using the global $_GET['id']. You can check if it is set, and depending on whether or not it is, show information regarding that id from the database.
It might look something like this:
if (isset($_GET["id"])) {
$id = $_GET["id"];
$query = "SELECT * table WHERE id = {$id} LIMIT 1;";
$result = mysqli_query($connection, $query);
while ($row = mysqli_fetch_assoc($result)){
echo $row["id"];
echo $row["name"];
echo $row["someOtherAttribute"];
}
}
Make sure you have your connection and your database set up and whatnot, but thats how you would accomplish this.

Mysqli get array from database and format to string [closed]

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 8 years ago.
Improve this question
I'm trying to get array of fields from database:
$query=("SELECT firstname FROM users");
$res = $connect->query($query);
Target is to display first name of every users:
echo $firstname
Output:
Firstname1,Firstname2,Firstname3
I know should be easy, if I just knew more.
For getting all records or a set of records you have to fetch each records inside a while loop.
$query=mysqli_query($connect,"SELECT firstname FROM users"); // execute the query
$string="";
while ($row = mysqli_fetch_array($query)) // fetch each records
{
$string.=$row['firstname']).','; // append the firstname to a variable
}
echo $string; // output the constructed variable with all firstnames

How to print data from SQL database to HTML table based on query [closed]

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 8 years ago.
Improve this question
so I have records in my database that I would like to print to a HTML table IF they belong to the user.
$sql="SELECT * FROM ".$tbl_name." WHERE Username='".$username."'";
The table would read :
Date, Room, Period , Cancel
With cancel being a red cross designed to delete that specific entry from the database :
Booking ID, Date, Period,Type,RoomID, Username are the fields in the database.
How would I go about doing this? I was thinking echoing a table using a for loop but I wouldn't know where to begin?
Try:
$query_rsSearch = "SELECT * FROM ".$tbl_name." WHERE Username='".$username."'";
$rsSearch = mysql_query($query_rsSearch) or die(mysql_error());
$row_rsSearch = mysql_fetch_assoc($rsSearch);
$totalRows_rsSearch = mysql_num_rows($rsSearch);
do {
echo $row_rsSearch['Date']." | ".$row_rsSearch['Room']." | ".$row_rsSearch['Period'];
} while($row_rsSearch = mysql_fetch_assoc($rsSearch));

Categories