PHP Gallery Problem - php

Ok, I have a gallery that's being populated by a database but for some reason it's not pulling entries from beyond May 31st 2011. I've scoured the code and can't find any date limitations so I'm at a loss as to why it's not pulling in any recent entries.
I've also looked through the database table and don't see any irregularities between pre May31st and more current entries.
<?php
//GALLERY PAGE
$user="USER";
$password = "PASSWORD";
$database = "GALLERY";
$hostname_portfolio ="localhost:3306";
//gets the page number from the URL
if($_GET["pageNum"]==''){
$listedNum=0;
//gets the page limit from the URL
$limit=5;
}
else{
$listedNum=$_GET["pageNum"];
//gets the page limit from the URL
$limit=$_GET["limit"];
}
//creates the list of projects and puts them into an array
$project= array();
$con = mysql_connect($hostname_portfolio,$user,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$dbcon = mysql_select_db("GALLERY", $con);
if (!$dbcon)
{
die('Could not connect: ' . mysql_error());
}
if ($dbcon)
{
}
mysql_select_db($database, $con);
$result = mysql_query("SELECT * FROM Persons ORDER BY date_uploaded DESC");
echo"<div class='clear' style='clear:both;'></div>";
$j=0;
do{
if($row['approved']=="true"){
$project[$j] =
"<div class='project-list'>
<div class='user-project'>
<div class='container'>
<div class='before-box' >
<p class='picture_state'>Before</p>
<a href='http://THEURL.com/". $row['image_path']."'>
<img src= '". $row['image_path']. "' width='400px' height='300px'/></a>
<br />
</div>
<div class='after-box'>
<p class='picture_state'>After</p>
<a href='". $row['picture_state']."'>
<img src= '". $row['picture_state']. "' width='400px' height='300px' /></a>
<br />
</div>
<div class='sidebox'>
<div class='inner-sidebox'>
<p class='date-project'>
Submitted by " . $row['FirstName'] . " " . $row['LastName']. " on " .$row['date_uploaded']. "</p>
<p> " .$row['decription']. "</p>";
if($row['ATTR1'] || $row['ATTR2']){
$project[$j] .= "<p>Used ";
if ($row['ATTR1']){
$project[$j] .= "PRODUCT2™";
if ($row['color1']){
$project[$j] .= " in " . $row['color1'];
}
if ($row['ATTR2']){
$project[$j] .= " and ";
}
}
if($row['ATTR2']){
$project[$j] .= "PRODUCT<sup>®</sup>";
if ($row['color2']){
$project[$j] .= " in " . $row['color2'];
}
}
$project[$j] .= "</p>";
}
$project[$j] .= "
</div>
</div>
</div>
<div class='clear' style='clear:both;'>
</div>
</div>
<div class='clear' style='clear:both;'>
</div>
</div>
<div class='clear' style='clear:both;'>
</div>";
$j++;
}
}
while($row = mysql_fetch_array($result));
$max=sizeof($project);
for($i=$listedNum;$i<$limit;$i++){
echo $project[$i];
}
$max=sizeof($project) - 1;
echo "<div class='bottom' style='width:170px;margin:0px auto;'>";
if($listedNum > 0){
$prevPageNum=$listedNum - 5;
$lastPage= $limit - 5;
echo "<a href='http://THEURL.com/gallery.php? pageNum=".$prevPageNum."&limit=".$lastPage."'>< Last Page </a>";
}
else{
$prevPageNum=$listedNum;
$lastPage= $limit;
}
echo" ";
if($limit <= $max){
$newPageNum=$listedNum + 5;
$nextPage= $limit + 5;
echo "<a href='http://THEURL.com/gallery.php?pageNum=".$newPageNum."&limit=".$nextPage."'> Next Page ></a>";
}
else{
$newPageNum=$listedNum;
$nextPage= $limit;
}
echo "</div>";
mysql_close($con);
?>

Im going to guess that its one of the following:
Youre server is only allowing you to pull 'x' amount of rows within each query (and that 'x' is dont at may 31st')
or theres something different with the files after may 31st. compared to the ones earlier

There's nothing in the code. It might be the way your database is configured where it only lets a certain number of results be returned and that happens to coincide with the date.

Check data in table. May be, after may 31st it was not "approved" ("approved" field was not set to something that casts to boolean TRUE)

Judging from your code - either date_uploaded is null in the records after May 31 or something else is wrong in your DB. Approved not equaling true on the offending records, for example.
Failing that, maybe it has something to do with this limitation. Try passing in a number higher than 5 and see if you get more records showing.
//gets the page number from the URL
if($_GET["pageNum"]==''){
$listedNum=0;
//gets the page limit from the URL
$limit=5;
}
else{
$listedNum=$_GET["pageNum"];
//gets the page limit from the URL
$limit=$_GET["limit"];
}

Related

how do i display mysql data in marquee?

i'm trying to use a marquee to display all the data from jobs table , but some how i can't display anything at all although it connects to the database successfully .so how can i display the data using marquee ?
<html>
<body>
<div class="box" STYLE="position:absolute; TOP:110px; LEFT:1100px;height: 470px;width : 200px;padding:10px;" >
<!-- STYLE="position:absolute; TOP:170px; LEFT:980px;height: 349px;width :360px;" -->
<u><font size="3" color="white">- Jobs may inters you :</font></u>
<br>
<marquee direction="up" scrollamount="2">
<p id="boxContent">
<script>
<?php
$conn = new Mysqli("localhost", "root", "", "ISNet");
if($conn->connect_error){
die("Connection failed:".$conn->connect_error);
}
$sql = "SELECT * FROM jobs";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<br> position - ". $row["position"]. "<br> company- ". $row["company"].
" <br> address -" . $row["Address"] ."<br> description - " . $row["description"] . " <br> mail -" . $row["mail"] .
"<br>";
echo "----------------------------------";
}
} else {
echo "0 results";
}
?>
</script></p>
</marquee>
</div>
</body>
</html>
This is what you do at the start of your marquee:
<marquee direction="up" scrollamount="2">
<p id="boxContent">
<script>
You open a script tag so everything you echo out, ends up inside the script tag and will be interpreted by the browser as javascript. So you will probably see a lot of errors in the console and your text in the source code.
Just remove the opening and closing script tags and you will have yourself a very cool retro marquee :-)

Why is my if statement skipping my else statement?

I have a piece of code, where every 20 mins, a system task runs a SQL query, adding to one of my database tables (tickets).
I have if if statement thats supposed to find than number (tickets) and use it to allow someone to "buy" items from my store.
It allows the user to buy more items, than they have tickets for (bringing their balance in to the negatives) like its just completely skipping my else statement. Is there something im doing wrong?
also thought i would add, the "tickets" column is INT and not like, VARCHAR or anything
the thing is also, it worked perfectly a few hours ago, so im not sure if i added something by accident, but now its not working
Be watching, the problem here is "if ($rewards > 4)"
http://prntscr.com/g79q3p
<div class="box">
<div class="contentHeader headerGreen">
<div class="inside">
5 Tickets
</div>
</div>
<ul>
<img src="/swf/c_images/album1584/2015HA.gif" align="right">
<li>25k Credits</li>
<li>25k Pixels</li>
<li>5 Diamonds
</ul>
<?php
if(isset($_POST['buy1'])) {
$getRewards = mysql_query("SELECT tickets FROM users WHERE id = '" . $_SESSION['user']['id'] . "'");
while($rewards = mysql_fetch_assoc($getRewards)) {
if($rewards > 4) {
mysql_query("UPDATE users SET tickets = tickets-5 WHERE id = '" . $_SESSION['user']['id'] . "'") or die(mysql_error());
mysql_query("UPDATE users SET credits = credits+25000 WHERE id = '" . $_SESSION['user']['id'] . "'");
mysql_query("UPDATE users SET activity_points = activity_points+25000 WHERE id = '" . $_SESSION['user']['id'] . "'");
mysql_query("UPDATE users SET vip_points = vip_points+5 WHERE id = '" . $_SESSION['user']['id'] . "'");
echo '
<div class="alert alert-sucess">
<strong>Well Done!</strong> Your items have been added.
</div>';
}
else if($rewards < 5) {
echo '
<div class="alert alert-error">
<strong>Error:</strong> You Do NOT Have Enough Tickets To Buy This
</div>';
}
/*else {
echo '
<div class="alert alert-error">
<strong>Error:</strong> You Do NOT Have Enough Tickets To Buy This
</div>';
}*/
}
}
?>
<form method='post'>
<input type="submit" value="Buy" name="buy1" style="width: 138px;cursor: pointer;" />
</form>
</div>
Please see how mysql_fetch_assocs works.
It returns an array. Does not matter how many fields you specify in sql - it is always an array.
Also do print_r and echo of your variables to see what is inside when it does not work.
if ($rewards["tickets"] > 4)
{
}
else if ($rewards["tickets"] < ....

How to change the "while" loop to retrieve only 3 top records from MySQL database

I set up the query to SELECT * FROM,
Then I used the while loop to print out all retrieved records and it all works fine.
But what I need is to print out only the TOP 3 of those records, is there any way to change that while loop to make it work this way.
Any help on this will be much appreciated, thx
while($row = $alerts_query->fetch_object()){
echo "<div class='panel'>
<div class='panel-heading'>
<h3 class='panel-title'>" . $row->ticket_title . " <a href='clientpanel.php?tab=dashboard=" . $row->ticketId . "' aria-hidden='true' type='button' class='close pull-right'>x</a></h3>
</div>
<div class='panel-body'>" . $row->ticket_description . "
<br />
<br />
<span style='color: #999'>Reported: " . $row->ticket_date . "</span>
</div>
</div>";
}
Do not limit in the while loop (though, it's possible). Change your SQL instead:
SELECT * FROM yourtable
Append:
SELECT * FROM yourtable LIMIT 3
If for some reason you should do it in PHP (not advised in this situation):
$i = 0;
while($row = $alerts_query->fetch_object() and $i<3) {
$i++;
// ...
}
Use:
SELECT * FROM [table] LIMIT 3
Use
SELECT * FROM table LIMIT x ORDER BY ASC
where x in your case is 3
It can achieved in many ways, using LIMIT clause is one of the approach. But following is according your scenario
$i = 1;
while ($row = $alerts_query->fetch_object()) {
if ($i > 3)
break;
echo "<div class='panel'>
<div class='panel-heading'>
<h3 class='panel-title'>" . $row->ticket_title . " <a href='clientpanel.php?tab=dashboard=" . $row->ticketId . "' aria-hidden='true' type='button' class='close pull-right'>x</a></h3>
</div>
<div class='panel-body'>" . $row->ticket_description . "
<br />
<br />
<span style='color: #999'>Reported: " . $row->ticket_date . "</span>
</div>
</div>";
$i++;
}
Try this
SELECT * FROM table LIMIT 0,3

PHP mysql_num_rows die error

I want to create one page, where users add their informations..
I allready have that page created, but my real problem its down code..
I have some kind of problem, with that part of code:
<?php
//Connect to DB
$db = mysql_connect("localhost","USER","PASS") or die("Database Error");
mysql_select_db("DB",$db);
//Get ID from request
$idstire = isset($_GET['idstire']) ? (int)$_GET['idstire'] : 0;
//Check id is valid
if($idstire > 0)
{
//Query the DB
$resource = mysql_query("SELECT * FROM stiri2 WHERE idstire = " . $idstire);
if($resource === false)
{
die("Eroare la conectarea cu baza de date");
}
if(mysql_num_rows($resource) == 0)
{
die("Se pare ca stirea nu mai exista, sau a fost stearsa. <a href='http://www.wanted-web.ro'>ACASA</a>");
}
$user = mysql_fetch_assoc($resource);
echo "
<div class='main-article-content'>
<h2 class='article-title'>asd</h2>
<div class='article-photo'>
<img src='" . $user['poza'] . "' class='setborder' alt='' />
</div>
<div class='article-controls'>
<div class='date'>
<div class='calendar-date'>" . $user['data'] . "</div>
</div>
<div class='right-side'>
<div class='colored'>
<a href='' class='icon-link'><span class='icon-text'></span>Printeaza articol</a>
<a href='#' class='icon-link'><span class='icon-text'></span>Trimite prietenilor</a>
</div>
<div>
<a href='#' class='icon-link'><span class='icon-text'></span>de Cristian Cosmin D.</a>
<a href='#' class='icon-link'><span class='icon-text'></span>39 comentarii</a>
</div>
</div>
<div class='clear-float'></div>
</div>
<div class='shortcode-content'>
<p>" . $user['nume'] . " , " . $user['prenume'] . " , " . $user['varsta'] . " , " . $user['localitatea'] . "</p>
</div>
</div>
";
}
$query = "UPDATE stiri2 SET accesari = accesari + 1 WHERE idstire=\"" . $idstire . "\"";
$result = mysql_query($query) OR die(mysql_error());
?>
It's show me error from here:
if(mysql_num_rows($resource) == 0)
{
die("Se pare ca stirea nu mai exista, sau a fost stearsa. <a href='http://www.wanted-web.ro'>ACASA</a>");
}
I really dont understand why!?
Can someone explain me?
Thank you!
mysql_query should have the second parameter as the connection which is in your case $db
$resource = mysql_query("SELECT * FROM stiri2 WHERE idstire = " . $idstire,$db);
if this also not works then use mysql_error to know the exact error
$row=mysql_num_rows($resource);
if($row)
{
}
else
{
mysql_error();
}
this will show you if there is problwm in mysql_num_rows
Well the problem is, that your SQL Statement does not have any results.
Please check if your database contains some rows for this idstire.
If $_GET['idstire'] is not set, you are setting $idstire to 0. Is there any entry in the table for idstire=0?
You can print your php query with $idstire replaced with its value. Take that query and execute in phpmyadmin to see the error. Also verify that row exists for the value of $idstire being used in the query.

Php search script to search all values in mysql table

I have a table of books which has info such as bname, bauthor, bdetails...etc
I want to provide a php script to search any thing from the table ...i tried a few scripts but it didnt work ..
Also i want to provide the option to provide option of selecting category ...
if the category is not selected then also the script should run...
Can anyone help me in this please ...
..
I m trying this :
$data = mysql_query("SELECT * FROM info WHERE upper($field) LIKE'%$find%'");
$result = mysql_query($data);
if (!$result) die ("DAtabase acces faild bc : ". mysql_error());
echo " <ul class=listbk>";
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo " <li class=bkd><a href=details.php?bid=".$row['pid']. "> <img src=images/".$row['bname']. ".jpg />
<ul class=showcasetitle> <span> ". $row['bname'] . " </span> </ul>
<p align=center style=text-align:center; font-size:10px;> By <span> ". $row['bauthor'] . "</span></p>
</a> <p align=center style=text-align:center; color: #F00;><span class=WebRupee style=color: #F00;>₹</span> ". $row['price'] . " only !!!</span></p>
</li> " ;
}
echo " </ul> ";
<?php
$text = 'John';
$query = "SELECT * FROM `books` WHERE MATCH(`bname`,`bauthor`,`bdetails`) AGAINST ('".$text."')";
?>

Categories