This my code:
<?php
$lijstDoelmannen = mysql_query("SELECT * FROM Speler WHERE positie = 'Doelman' ORDER BY familienaam, voornaam");
$teller = 1;
while($rij = mysql_fetch_array($lijstDoelmannen))
{
if($teller < 5){
echo "<td><a href='spelerDetail.php?spelerId='" . $rij['id'] . "><img src='images/spelers/unknown.png' alt='' width='50' />
<br /><br />" . $rij["id"] . " " . $rij['familienaam'] . " " . $rij['voornaam'] . "</a></td>";
}
}
?>
The problem is that in the hyperlink the parameter spelerId = spaces (not filled in). If I echo $rij["id"], it gives me the right value.
You have a ' in the wrong spot in your href.
"...<a href='spelerDetail.php?spelerId='" . $rij['id'] . ">..."
This should be:
"...<a href='spelerDetail.php?spelerId=" . $rij['id'] . "'>..."
<a href='spelerDetail.php?spelerId='" . $rij['id'] . ">
You need to move the apostrophe:
<a href='spelerDetail.php?spelerId=" . $rij['id'] . "'>
It's currently ending the link, before the variable is added.
You can also do:
echo "<td><a href='spelerDetail.php?spelerId={$rij['id']}'
while($rij = mysql_fetch_array($lijstDoelmannen))
{
if($teller < 5){
echo "<td><a href='spelerDetail.php?spelerId='" . $rij['id'] . "><img src='images/spelers/unknown.png' alt='' width='50' />
<br /><br />" . $rij["id"] . " " . $rij['familienaam'] . " " . $rij['voornaam'] . "</a></td>";
}
}
?>
I prefer writing the above code this way to avid these types of issues:
while($rij = mysql_fetch_array($lijstDoelmannen)){
if($teller < 5){ ?>
<td><a href="spelerDetail.php?spelerId=<?php echo $rij['id'] ?>">
<img src="images/spelers/unknown.png" alt="" width="50" />
<br /><br /><?php echo $rij['id'] . " " . $rij['familienaam'] . " " . $rij['voornaam'] ?></a></td>
<?php }} ?>
Related
How do I echo a variable inside the tag? this code does not seem to work. Any help is appreciated.
echo "<a href='productdetails.php?image="$results['image']"'><img src='images/".$results["image"]."' class='img-responsive' /></a><br />";
Like this
echo "<a href='productdetails.php?image="{$results['image']}"'>
<img src='images/{$results["image"]}' class='img-responsive' />
</a><br />";
Or
echo "<a href='productdetails.php?image=$results[image]'>
<img src='images/$results[image]' class='img-responsive' />
</a><br />";
Or like your original but with the correct concatenation
echo "<a href='productdetails.php?image=" . $results['image'] . "'>
<img src='images/".$results["image"]."' class='img-responsive' />
</a><br />";
It should be like this, you missed . before and after $results['image'], so proper concatenation is not happening:
echo "<a href='productdetails.php?image=" . $results['image'] . "'><img src='images/" . $results["image"] . "' class='img-responsive' /></a><br />";
Method 2:
Take it in a variable:
$image = $results['image'];
echo "<a href='productdetails.php?image=" . $image . "'><img src='images/" . $image . "' class='img-responsive' /></a><br />";
Or like this:
echo
'<a href="productdetails.php?image=' . $results['image'] . '">
<img src="images/' . $results['image'] . '" class="img-responsive" />
</a><br />';
i want know how I can save a result i fetched from my database back into the database.
I selected and fetched a row from a table in my database, there is a column from the row i want to insert in another table in the same database. I tried to turn the $row['example']; to a variable but it wont work, i echo the variable to be sure if its working but its not showing .
please i need a help , below is my codes.
<?php
$query =mysqli_query ($dbconnect, "select * from stuprofile where username ='$user' limit 1");
while ($row= mysqli_fetch_assoc($query)){?>
<?php
$uname= "USERNAME :";
$ebc= "EBC16";
$id ="MATRIC NO : ";
$wel = "WELCOME ";
$name ="FIRSTNAME : ";
$lname ="LASTNAME : ";
$sex ="SEX : ";
$add ="ADDRESS : ";
$mob ="MOBILE : ";
$inst ="INSTITUTION : ";
$chap ="CHAPTER : ";
$marr ="MARITAL STATUS : ";
$lc ="LOCAL CHURCH : ";
$bap ="BAPTISM : ";
$baptised ="BAPTISED : ";
$bank ="BANK : ";
$teller ="TELLER NUMBER : ";
$pay ="PAYMENT NUMBER : ";
$email ="EMAIL : ";
// dont forget to style your above varibles
//<span id ="ty">
?>
<div class="wel">
<?php
echo "<p>" . $wel . "<div id='ten' >" . " " . $row['firstname'] . " " . $row['lastname'] . "</div>" . "<p>" . "<br />" ;
?>
</div>
<!--<section><img src= "images/egliselogocomp.jpg" height="310" width: 50px> </section>-->
<p class= "names">
<?php
echo
$id . "<span >" . $ebc . $row['id']. "</span >" . " <br />" .
$name . "<span >" . $row['firstname']. "</span >" . "<br />" .
$lname . "<span >" .$row['lastname']. "</span >" . "<br />" .
$uname . "<span >" .$row['username']. "</span >" . "<br />" .
$sex . "<span >" .$row['sex'] . "</span >" . "<br />" .
$add . "<span >" .$row['address']. "</span >" . "<br />" .
$email . "<span >" .$row['email']. "</span >" . "<br />" .
$mob . "<span >" .$row['mobile']. "</span >" . "<br />" .
$inst . "<span >" .$row['institution']. "</span >" . "<br />" .
$chap . "<span >" .$row['chapter']. "</span >" . "<br />" .
$marr . "<span >" .$row['marital_status']. "</span >" . "<br />" .
$lc . "<span >" .$row['local_church']. "</span >" . "<br />".
$bap . "<span >" .$row['baptised']. "</span >" . "<br />" .
$baptised . "<span >" .$row['baptism']. "</span >" . "<br />" .
$bank . "<span >" .$row['bank']. "</span >" . "<br />" .
$teller . "<span >" .$row['teller_no']. "</span >" . "<br />".
$pay . "<span >" .$row['payment_date']. "</span >" . "<br />";
}
?>
</p>
<?php
} else {
header("location: ebcreg.php");
}
I need to insert the . $ebc . $row['id'] back into the database.
How do I do that please.
thanks
mysqli_query($dbconnect, "INSERT INTO ....");
The same way you selected your data, just change your query.
Hi guys I have a problem with my PHP, What I am trying to achieve is this:
<li>Product name from DB
<strong>£499<img src="images/thumb.png" alt="Product name from DB"/></strong>
</li>
and here is my code with php:
<ul id="items">
<?php while($product_data = mysql_fetch_array($query_product_result))
{
$num_rows_products = $num_rows_products - 1;
Print "<li><a href = 'main.php?prodid=" . $product_data["product_id"] . " <strong> Name: " . $product_data["title"] . "</strong></a>";
Print "<strong>Price: £" . $product_data["price"] . "'><img src='images/" . $product_data["mainImageThumbnail"] . "' alt='Product image' /></a></strong></li>";
if($num_rows_products > 0)
Print '<p> nu products ? wtf</p>';
}
?>
For some reason all I get is an image with a hyperlink, no title and no price, any chance you can spot the mistake?
Your not closing the <a> tag properly. See the code below. Notice the missing ">" in your code?
Print "<li><a href = 'main.php?prodid=" . $product_data["product_id"] . "'> <strong> Name: " . $product_data["title"] . "</strong></a>";
Print "<strong>Price: £" . $product_data["price"] . "<img src='images/" . $product_data["mainImageThumbnail"] . "' alt='Product image' /></a></strong></li>";
Use Echo instead. Print won't displays concatenated string.
<ul id="items">
<?php while($product_data = mysql_fetch_array($query_product_result))
{
$num_rows_products = $num_rows_products - 1;
echo "<li><a href = 'main.php?prodid=" . $product_data["product_id"] . " <strong> Name: " . $product_data["title"] . "</strong></a>";
echo "<strong>Price: £" . $product_data["price"] . "'><img src='images/" . $product_data["mainImageThumbnail"] . "' alt='Product image' /></a></strong></li>";
if($num_rows_products > 0)
echo '<p> nu products ? wtf</p>';
}
?>
I am trying to perform several line break (br) in my table cell.
But I have problem with the syntax.
Below is my code to perform line break (br) within a single cell, but it doesn't work.
How should I go about doing it?
echo("<tr><td>".$row[0].
<br/>
$row[1].
<br/> $row[2].
<br/>
"<img src=images/".$row["skuCode"]."_1.jpg>".
<br/>
View".
"</td></tr>");
You're not using quotes properly, but I think it would be much easier to use a heredoc.
echo <<<HTML
<tr><td>$row[0]<br/>$row[1]<br/>$row[2]<br/>
<img src=images/$row[skuCode]_1.jpg<br/>
<a href=viewProductItem.php?skuCode=$row[0]>View</a>
</td></tr>
HTML;
You forgot the quotes around the <br/>s , try:
echo("<tr><td>".$row[0].
"<br/>" .
$row[1].
"<br/>". $row[2].
"<br/>" .
"<img src=images/".$row["skuCode"]."_1.jpg>".
"<br/>".
"View".
"</td></tr>");
Or alternatively:
echo("<tr><td>{$row[0]}
<br/>
{$row[1]}
<br/> {$row[2]}
<br/>
<img src=images/.$row[skuCode]._1.jpg>
<br/>
<a href=viewProductItem.php?skuCode={$row[0]}>View</a>.
</td></tr>");
You forgot to open and close the quotes in your string:
<?php
echo "<tr><td>".$row[0]."<br/>".$row[1]."<br/>".$row[2]."<br/><img src=images/".$row["skuCode"]."_1.jpg><br/>View</td></tr>";
?>
Try this:
echo "<tr><td>{$row[0]}<br/>{$row[1]}<br/>{$row[2]}<br/><img src=\"images/{$row['skuCode']}_1.jpg\"><br/>View</td></tr>";
You forgot to wrap the br tags around brackets, also you can use curly braces to never have to exit out of your string and concat it in php
echo "String with $variable works";
echo "String with {$array['key']} works with curly bracers."
If you want to make its HTML output well-formatted, then you could check this:
echo "<tr>\n";
echo " <td>" . $row[0] . "<br />\n";
echo " " . $row[1] . "<br />\n";
echo " " . $row[2] . "<br />\n";
echo ' <img src="images/' . $row["skuCode"] . '_1.jpg"><br />' . "\n";
echo ' View</td><br />' . "\n";
echo "</tr>\n";
Or this:
echo "<tr>\n";
echo " <td>" . $row[0] . "<br />\n";
echo " " . $row[1] . "<br />\n";
echo " " . $row[2] . "<br />\n";
echo " <img src=images/" . $row["skuCode"] . "_1.jpg><br />\n";
echo " View</td><br />\n"
echo "</tr>\n";
Or if you did not like those, look at this:
echo("<tr><td>" . $row[0] . "\n" .
"<br />\n" .
$row[1] . "\n" .
"<br />" . $row[2] . "\n" .
"<br />\n" .
"<img src=images/" . $row["skuCode"] . "_1.jpg>\n" .
"<br />\n" .
"View\n" .
"</td></tr>\n");
I am trying to get rid of the border space between the cells. I thought cellspacing would do the trick but there is still a slim white border. Can anyone give me some advice...
<body>
<center><table style="cellspacing:0; width:400px; border:none;">
<?
echo "<tr><td> Team </td><td>Correct Picks</td><td>Points</td></tr>";
while($row = mysql_fetch_array($memberslist)) {
if ($row['User_ID'] == $id) {
echo "<tr bgcolor=\"gray\"><td>" . $row['User_ID'] . "</td><td><b>" . $row['Correct_Picks'] . " </b> /" . $maxcorrectpicks . "</td><td>" . $row['Points'] . "</td></tr>";
} else {
echo "<tr><td>" . $row['User_ID'] . "</td><td><b>" . $row['Correct_Picks'] . " </b> /" . $maxcorrectpicks . "</td><td>" . $row['Points'] . "</td></tr>";
}
}
?>
</table></center>
</body>
cellspacing=0;
is no CSS. That was once a HTML attribute:
<table cellspacing="0" style="width:400px">
See as well the related (duplicate?) question:
How to set cellpadding & cellspacing in CSS?