I want to get the registered users list on a page but not just their names, but with clickable hyperlink that will lead to their profiles. I have fetched their names but just in text form but how to add hyperlink to that text so that link should lead to their profile.
<?php
$con=mysqli_connect("localhost","root","","dva");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM apnt");
while($row = mysqli_fetch_array($result)) {
echo "<li>";echo "User Reg.";
echo $row['name'];
echo " at ";
echo $row['time'];
echo " on ";
echo $row['day'];
echo "<br>";
echo "<br>";
;
}
mysqli_close($con);
?>
I have got the data from the database and successfully printed it on the page via above code but the hyperlink still needs to be generated and I need help in that please.
Create a profile.php and use GET to get the id number of your user which you send through with the link you create where you fetch your users.
Related
use php variable in name of mysql create table
I want to use a PHP variable ( $userAltId ) as the name of the SQL table I am creating. However, despite looking at several examples, I have been unable to successfully create a table with this PHP variable. Using echo I have shown that the variable ( $userAltId ) does contain the predicted value, and if I plug in that value instead of the variable I can successfully create the table.
My latest attempt at the code is below, notice I use $useAltId three times, from creating, inserting, and selecting. Thanks for the help!
<?php
$con=mysqli_connect('localhost', 'alexpnqo_johnny', '?KlI+TtfNEIO', 'alexpnqo_johnny');
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
session_start();
$userAltId = $_SESSION['userAltId'];//I am passing $userAltId from another php file
// escape variables for security
$FBname = mysqli_real_escape_string($con, $_POST['FBname']);
echo $userAltId;//echos desired value
$sqlFriendList="INSERT INTO '$userAltId' (FacebookFriend)
VALUES ('$FBname')";
if (mysqli_query($con,$sql)) {
echo "Table created successfully";
} else {
echo "Error creating table: " . mysqli_error($con);";
}
echo "You have added ";
echo $FBname;
echo " to your friend's list!";
echo "<br>";
echo "Below is your friends list";
echo "<br>";
echo "<br>";
$result = mysqli_query($con, "SELECT FacebookFriend FROM '$userAltId'");
echo "<table border='1'>
<tr>
<th>Friends List</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['FacebookFriend'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Use backticks $userAltId to all your queries (table name) so that it'll read your variable even spaces.
$sqlFriendList="INSERT INTO `$userAltId` (FacebookFriend) VALUES ('$FBname')";
I'm trying to create a simple e-commerce system. First thing I did was select the rows with the same Order ID from mysql. My table looks like this:
Now, I'd like to know how I can group them into separate divs, it should look like this:
Here's my code:
$con = mysqli_connect("localhost","root","","test");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result2 = mysqli_query($con, "SELECT DISTINCT request_date, department_id FROM tbl_requests WHERE request_id=".$_GET['request_id']) ;
while($row2 = mysqli_fetch_array($result2)) {
echo "" . $row2['request_date'] . "<br/>";
echo "Order from Department " . $row2['department_id'] . "<br/>";
echo "<br/>";
echo "<hr/>";
echo "<br/>";
}
$result = mysqli_query($con,"SELECT * FROM tbl_requests WHERE request_id=".$_GET['request_id']);
while($row = mysqli_fetch_array($result)) {
echo "" . $row['request_details'] . "";
echo "<br/>";
}
I'm sorry if ever this question is incomplete, please feel free to ask me any more questions. Thank you in advance :)
You can check for every product in array using Javascript or jQuery(much easier).
This way you can check if your page does contain any existing div with that manufacture id (ie. #m_1055, #m_1040) or not.
If div does exist, append product in that div (in jQuery.append())
If not, then first append the div with that manufacture id to the document and then append the product to it.
Very new to PHP so please go easy on me :)
I need to show the product details (manufacturer, tag number, etc) of a product if it's clicked by the user after being shown the results page. User types in a search form initially, then I get the catalogue_query.php to show the results, images, etc, that's all good. Each product has its own unique id which I thankfully get it to show in the url of the details.php page so I am doing something right.
However when I click on an item, even though I do get the "details.php" page shown with the correct id in the URL all it returns is the image and details for the very first item in the DB, not the actual item I clicked on - in other words the image and details do not match the id in the url.
Here is my code to show the results:
<?php
$query = $_POST ['query'];
$db = mysqli_connect ('localhost','root','root','asset_catalog');
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($db,"SELECT * FROM assets WHERE Description LIKE '%$query%' OR Manufacturer LIKE '%$query%' ORDER BY Description ");
echo "<table border='0'>
<tr>
</tr>";
while($row = mysqli_fetch_array($result))
{
if (($i % 5) == 0) echo "<tr>";
echo "<td><img src='".$row['Image']."' id='queryimg'><br>
<a href='details.php?ID=".$row['ID']."' style='color: #fff;'>{$row[Description]}</a></td>";
if (($i % 5) == 4) echo "</tr>";
$i++;
}
if ( $i > 0 && ($i-1) % 3 < 2) echo "</tr>";
echo "</table>";
?>
And here is my php for the details.php page:
<?php
$db = mysqli_connect ('localhost','root','root','asset_catalog');
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$ID = isset($_GET['ID']) ? (int) $_GET['ID'] : null;
$result = mysqli_query($db,"SELECT * FROM assets WHERE ID = $ID");
$row = mysqli_fetch_array($result);
echo "<table border='0'>
<tr>
</tr>";
echo "<tr>";
echo "<td><img src='".$row['Image']."' id='queryimg_details'>
<br>
{$row[Description]}</a>
<br>
{$row[Manufacturer]}
<br>
{$row[Tag_Num]}</td>";
echo "</tr>";
?>
Could anyone point me in the right direction? I am lost as to what I am doing wrong - or not doing.
Thanks a lot in advance!
$row can have multiple entries, so you should loop over it:
foreach($row as $r) {
// do stuff with this row like $r['Image']
}
You might want to change the variables names too.
I have a table with arrays pulling information from a database, I have linked the fix to be a hyperlink "click me for fix" I have entered the link to send the variable to a php that will use $GET to echoe the information.
code below , i am new to php and been racking brains . the only out put i get is Welcome . (done welcome to test if information was being passed)
<div id=list>
<?php
// Create connection
$con=mysqli_connect('172.16.254.111',"user","password","Faults"); //(connection location , username to sql, password to sql, name of db)
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//where statement in the sql syntax will select where in db to get infor, use AND to add another condition
$result = mysqli_query($con,"SELECT * FROM Fixes WHERE Product='Serv1U' AND Fault_type='Broadcast Manager'"); //this creates a variable that selects the database
//below is the echo statment to create the results in a table format, list collumn titles
echo "<table id=tables border='1'>
<tr>
<th>Products</th>
<th>Fault_type</th>
<th>Fault_Description</th>
<th>Fix</th>
</tr>";
//below is script to list reults in a table format, $row [row name on table]
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Product'] . "</td>";
echo "<td>" . $row['Fault_type'] . "</td>";
echo "<td>" . $row['Fault_Description'] . "</td>";
echo "<td>Click for Fix</td>"; //this is how you link into an echo, alsothe id=" hopefully means i can send ID information.
}
echo "</tr>";
echo "</table>";
// below closes the coonection to mysql
mysqli_close($con);
index.php:
Welcome <?php echo $_GET["Fix"]; ?>.
I'm lost. Any help is appreciated.
Thanks
?>
Is it just a typo here? $GET must be $_GET.
And it should be $row['Fix'] not $rows['Fix']! Note the 's'!
I've been trying for hours to figure out how to put a link into the following text output via PHP echo(). I basically want to make the title field I'm pulling from my events table (as seen in #4 in the code below) to come back into the browser as a link instead of just text...
the original code that brings back the event title:
<?php
// 3. Perform database Query to bring list of events
$result = mysql_query("SELECT * FROM events", $connection);
if (!$result) {
die("Database query failed: " . mysql_error());
}
// 4. Use returned Data
while ($row = mysql_fetch_array($result)) {
echo $row ["eventtitle"]."<br/>".$row["eventdesc"]."<br/>";
}
?>
How would I go about getting that $row["eventtitle"] to appear in the browser as a link? Let's say if the link was just "eventprofile.php". This is probably an easy fix, but I've been getting a million errors with trying different things with <a href>s.
<?php
$result = mysql_query("SELECT * FROM events", $connection);
if (!$result) {
die("Database query failed: " . mysql_error());
}
while ($row = mysql_fetch_array($result)) {
echo "".$row["eventtitle"]."<br/>".$row["eventdesc"]."<br/>";
}
?>
add an anchor tag for it!!
echo "" . $row['eventtitle'] . '' . "<br />" .$row["eventdesc"]."<br/>";
And thats it.