I want to add three class for bottom of pagination where show page number , I used that in PHP but I can't figure out where to put class name inside of php echo to make work... because i'm getting errors...
class="box_one" for ... << Prev Page
class="box_two" for ... echo $thenumrows or $i
class= "box_three" ... Next Page >>
here is code...
<?php
if ($thenumrows != "")
{
echo "<br>";
if ($thecurrentpage > 1)
echo "<a href='". $_SERVER['PHP_SELF'] . "?cat= ". $theselectedcat ."&rows= "
. $thenumrows ."&page=". $thepreviouspage ."'>
<< Prev Page </a> "; for ($i=1;$i<=$totalpages;$i++)
{
if ($i == $thecurrentpage)
echo $i ." ";
else
echo "<a href='". $_SERVER['PHP_SELF'] ."?cat=". $theselectedcat ."&rows=".
$thenumrows ."&page=". $i ."'>$i</a> ";
}
if ($thecurrentpage < $totalpages)
echo "<a href='". $_SERVER['PHP_SELF'] ."?cat=". $theselectedcat ."&rows=".
$thenumrows ."&page=". $thenextpage ."'>Next Page >></a> ";
}
?>
please help thanks.
AM
I had to clean up your code. The classes are added to the a-tags:
if ($thenumrows != "") {
echo "<br />";
// Back
if ($thecurrentpage > 1) {
echo '<a class="box_one" href="'. $_SERVER['PHP_SELF'] . '?cat=' . $theselectedcat . '&rows=' . $thenumrows . '&page=' . $thepreviouspage . '"><< Prev Page</a> ';
}
// Paginating
for ($i=1; $i<=$totalpages; $i++) {
if ($i == $thecurrentpage) {
echo '<span class="box_two">' . $i .'</span> ';
}
else {
echo '<a class="box_two" href="' . $_SERVER['PHP_SELF'] . '?cat=' . $theselectedcat . '&rows=' . $thenumrows . '&page=' . $i . '">' . $i . '</a> ';
}
}
// Next
if ($thecurrentpage < $totalpages) {
echo '<a class="box_three" href="' . $_SERVER['PHP_SELF'] . '?cat=' . $theselectedcat . '&rows=' . $thenumrows . '&page=' . $thenextpage .'">Next Page >></a> ';
}
}
?>
Related
I have this page that looks a little like this.
<div class="ecigcontainer">
<div class="backbutt"><?php include("php/back.php"); ?></div>
<div class="ecig"><?php include("php/ecig.php"); ?></div>
<div class="forwardbutt"><?php include("php/forward.php"); ?></div>
</div>
A back button that works like this.
<?php
if (isset($_GET["ecig"])) {
$back = $_GET["ecig"] - 1;
echo "<a href=\"?ecig=" . $back . "\">";
echo "<img src=\"images/ecigs/" . $back . ".png\" height=\"300px\" /></a>";
} else {
$back = $_GET["ecig"] - 1;
echo "<a href=\"?ecig=" . $back . "\">";
echo "<img src=\"images/ecigs/" . $back . ".png\" height=\"300px\" /></a>";
}?>
The forward button pretty much has the same code, and the display looks like this.
<div class="ecigpic">
<img src="images/ecigs/<?php include("php/ecigcounter.php"); ?>.png" height="400px" />
</div>
<div class="ecigdesc">
<?php
if (isset($_GET["ecig"])) {
include("ecigs/" . $_GET["ecig"] . ".php");
echo "<h3>" . $ecigname . "</h3>";
echo "<p>" . $ecigdesc . "</p>";
} else {
$_GET["ecig"] = 1;
include("ecigs/" . $_GET["ecig"] . ".php");
echo "<h3>" . $ecigname . "</h3>";
echo "<p>" . $ecigdesc . "</p>";
}?>
</div>
With the "ecigcounter" that does this.
<?php
if (isset($_GET["ecig"])) {
echo $_GET["ecig"];
} else {
$_GET["ecig"] = 1;
echo $_GET["ecig"];
}?>
But the whole reason for this question is, how to I make it so it only displays numbers 1-40? Kind of lost and can't really seem to figure it out, and put it where it needs to go.
All the it needed was
<?php
if (isset($_GET["ecig"])) {
if ($_GET["ecig"] == 1){
$back = 40;
echo "<a href=\"?ecig=" . $back . "\">";
echo "<img src=\"images/ecigs/" . $back . ".png\" height=\"300px\" /></a>";
} else {
$back = $_GET["ecig"] - 1;
echo "<a href=\"?ecig=" . $back . "\">";
echo "<img src=\"images/ecigs/" . $back . ".png\" height=\"300px\" /></a>";
}
} else {
$back = $_GET["ecig"] - 1;
echo "<a href=\"?ecig=" . $back . "\">";
echo "<img src=\"images/ecigs/" . $back . ".png\" height=\"300px\" /></a>";
}?>
This little script made the world.
if ($_GET["ecig"] == 1){
$back = 40;
echo "<a href=\"?ecig=" . $back . "\">";
echo "<img src=\"images/ecigs/" . $back . ".png\" height=\"300px\" /></a>";
I'm trying to do a condition within an if statement.
I have a current if statement which determines odd and even for css styling.
Within this I want to add another if statement for the reference number. (outlined as Ref in the code).
I'm not sure how to go about this but I want to add something along the lines of
if ref == 1 then echo ref, I've tried putting an if within an if and I just keep getting syntax errors. Can someone point me in the right direction please?
include "db_connect.php";
$result1 = mysql_query("SELECT * FROM updates ORDER BY id DESC limit 5");
$result2 = mysql_num_rows($result1);
$x = $result2;
while ($row1 = mysql_fetch_array($result1)) {
if (++$x % 2) {
echo "<blockquote class='example-right'>" . $row1['update'] .
"<div class='ref'>Ref: " . $row1['ref'] .
"</div><div class='date-right'> from " . $row1['date'] .
" to " . $row1['todate'] .
"</div> </blockquote> <p>" . $row1['username'] .
"</p> </td>";
echo "</p>";
} else {
echo "<blockquote class='example-obtuse'>" . $row1['update'] .
"<div class='ref'>Ref: " . $row1['ref'] .
"</div><div class='date-right'> from " . $row1['date'] .
" to " . $row1['todate'] .
"</div> </blockquote> <p>" . $row1['username'] .
"</p> </td>";
}
}
the bit I tried to do with 2nd if statement:
include "db_connect.php";
$result1 = mysql_query("SELECT * FROM updates1 ORDER BY id DESC limit 5");
$result2 = mysql_num_rows($result1);
$x = $result2;
while ($row1 = mysql_fetch_array($result1)) {
if (++$x % 2) {
$sch = $row1['schuedled'];
else if ($sch == '1') {
echo "<blockquote class='example-right'>" . $row1['update'] .
"<div class='ref'>Ref: " .$row1['ref'] .
"</div><div class='date-right'> from " . $row1['date'] .
" to " . $row1['todate'] .
"</div> </blockquote> <p>" . $row1['username'] .
"</p> </td>";
else {
echo "<blockquote class='example-right'>" . $row1['update'] .
"</div><div class='date-right'> from " . $row1['date'] .
" to " . $row1['todate'] .
"</div> </blockquote> <p>" . $row1['username'] .
"</p> </td>";
}
}
echo "</p>";
} else {
echo "<blockquote class='example-obtuse'>" . $row1['update'] .
"<div class='assyst-ref'>Ref: " . $row1['ref'] .
"</div><div class='date-right'> from " . $row1['date'] .
" to " . $row1['todate'] .
"</div> </blockquote> <p>" . $row1['username'] .
"</p> </td>";
}
}
Try something like this:
while($row1 = mysql_fetch_array($result1)){
$html = '';
if (++$x % 2 ){
$html .= "<blockquote class='example-right'>";
} else {
$html .= "<blockquote class='example-obtuse'>";
}
$html .= $row1['update'];
if($row1['schuedled'] == '1'){
$html .= "<div class='ref'>Ref: " .$row1['ref'] . "</div>";
}
$html .= "more html";
$html .= "more html";
$html .= "more html";
$html .= "</blockquote>";
echo $html;
}
Im wondering if its possible with PHP to add a class to X record returned. I know I can do this with JS only I'd like it to have the class added as the records are returned.
I have the following loop in my PHP, From what I've found in google I need to add a counter to do this only I've been unsuccessful so far...
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
echo '<div class="entry span3"><span class="name">' . $row['First_Name'] . ' ' . $row['Surname'] . "</span>";
echo '<img src="' . $row["picture_1"] . '" alt="' . $row['First_Name'] . ' ' . $row['Surname'] . ', text ' . $row['Date'] . ' ">';
echo '<span class="from">seen in ' . ucwords($row["Location_County__Seen"]) . '</span>View Profile</div>';
}
In front of your while, add $c = 1
Before the end of your while loop, add $c++;
Then, modify your first line:
echo '<div class="entry span3"><span class="name">'
To
echo '<div class="entry span3';
if (($c % 4) == 1) echo ' newclassname ';
echo '"><span class="name">'
For the final result:
$c = 1;
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
echo '<div class="entry';
if (($c % 4) == 1) echo ' newclassname ';
echo ' span3"><span class="name">' . $row['First_Name'] . ' ' . $row['Surname'] . "</span>";
echo '<img src="' . $row["picture_1"] . '" alt="' . $row['First_Name'] . ' ' . $row['Surname'] . ', text ' . $row['Date'] . ' ">';
echo '<span class="from">seen in ' . ucwords($row["Location_County__Seen"]) . '</span>View Profile</div>';
$c++;
}
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 }} ?>
Simple question I believe for anyone with minimal php skills (which I don't have sufficient amounts of haha)
$numrows = $retour['nb'] / 4;
echo $numrows;
echo "<table><tr>";
while ($callback = mysql_fetch_assoc($queryLocations2))
{
echo utf8_encode('<td><img src="/flags/' . strtolower($callback['loc_code']) . '.png" id="' . $callback['loc_id'] . '"><input type="checkbox" value="' . $callback['loc_url'] . '" />' . $callback['loc_city'] . ', ' . utf8_encode($callback['loc_state']) . '</td>');
}
echo "</tr></table>";
}
How would I go about presenting a table that will hold 4 results(4 columns) per row, based on the value of $numrows?
Thank you!
Output tr tags inside while loop:
$count = 0;
echo "<table>";
while ($callback = mysql_fetch_assoc($queryLocations2))
{
if ($count % 4 == 0)
echo '<tr>';
$count++;
echo utf8_encode('<td><img src="/flags/' . strtolower($callback['loc_code']) . '.png" id="' . $callback['loc_id'] . '"><input type="checkbox" value="' . $callback['loc_url'] . '" />' . $callback['loc_city'] . ', ' . utf8_encode($callback['loc_state']) . '</td>');
if ($count % 4 == 0)
echo '</tr>';
}
if ($count % 4 != 0)
{
// need to add missing td-s here
echo '</tr>';
}
echo "</table>";
$numrows = floor($retour['nb'] / 4);
echo $numrows;
$i=0;
echo "<table>";
while ($callback = mysql_fetch_assoc($queryLocations2))
{
if($i==4)
{
echo "<tr>";
echo utf8_encode('<td><img src="/flags/' . strtolower($callback['loc_code']) . '.png" id="' . $callback['loc_id'] . '"><input type="checkbox" value="' . $callback['loc_url'] . '" />' . $callback['loc_city'] . ', ' . utf8_encode($callback['loc_state']) . '</td>');
echo "</tr>";
$i=0;
}
$i++;
}
while ($i<4)
{
echo '<td></td>';
$i++;
}
echo "</table>";
}
//if numrows used for # of rows then use following
$count=0;
while ($callback = mysql_fetch_assoc($queryLocations2) && $count<=$numrows)
{
if($i==4)
echo "<tr>";
echo utf8_encode('<td><img src="/flags/' . strtolower($callback['loc_code']) . '.png" id="' . $callback['loc_id'] . '"><input type="checkbox" value="' . $callback['loc_url'] . '" />' . $callback['loc_city'] . ', ' . utf8_encode($callback['loc_state']) . '</td>');
if($i==4)
{
echo "</tr>";
$i=0;
$count++;
}
$i++;
}
while ($i<4)
{
echo '<td></td>';
$i++;
}
echo "</table>";
}