I have a search form the searches through a packaging database. Everything works fine and dandy, when the search from is submitted I get returned results on a different page displayed in styled boxes with a picture. But unfortunately the seem to display one after another underneath each other. Although it is good that they are returning and I am getting the correct results. I want to be able to display three next to each other, then they go to the next row and display three more, so on and so forth until I have run out of results.
Here is the PHP:
<?php
$con = mysql_connect ("localhost", "horizon1", "D2j616H5O#Lw");
mysql_select_db ("horizon1_delyn", $con);
if (!$con)
{
die ("Could not connect: " . mysql_error());
}
$descrip = mysql_real_escape_string($_POST['descrip']);
$depth = mysql_real_escape_string($_POST['depth']);
$varWidth = mysql_real_escape_string($_POST['traywidth']);
$varHeight= mysql_real_escape_string($_POST['trayheight']);
$varRange = mysql_real_escape_string($_POST['trayrange']);
$varType = mysql_real_escape_string($_POST['traytype']);
$varShape = mysql_real_escape_string($_POST['trayshape']);
$varImage = mysql_real_escape_string($_POST['imagename']);
if (isset($varHeight) && !empty($varHeight)) {
$low = ($varHeight."00");
$high = ($varHeight."99");
} else {
$low = ("000");
$high = ("999");
}
if (isset($varWidth) && !empty($varWidth)) {
$min = ($varWidth."00");
$max = ($varWidth."99");
} else {
$min = ("000");
$max = ("999");
}
$sql = "SELECT * FROM range WHERE
description LIKE '%".$descrip."%'
AND trayrange LIKE '%".$varRange."%'
AND traytype LIKE '%".$varType."%'
AND trayshape LIKE '%".$varShape."%'
AND traywidth BETWEEN '".$min."' AND '".$max."'
AND trayheight BETWEEN '".$low."' AND '".$high."' ";
$r_query = mysql_query($sql);
while ($row = mysql_fetch_array($r_query))
{
echo '<div id="results">';
echo '<p class="image">
<img src=" '. $row['imagename'] . '" width="150" length="80">
</p>';
echo '<div id="table"><br />
<strong> Tool Code: </strong> '. $row['toolcode'];
echo '<br /><strong> Description: </strong> '. $row['description'];
echo '<br /><strong> Tray range: </strong> '. $row['trayrange'];
echo '<br /><strong> Tray type: </strong> '. $row['traytype'];
echo '<br /><strong> Tray size: </strong> '. $row['traysize'];
echo '<br /><strong> Tray shape: </strong> '. $row['trayshape'] . '</div>' . '<br />';
echo 'Enquiry Page <br />' .
'Back to Search';
echo '</div>' . '<br />';
}
if (mysql_num_rows($r_query) <= 0){
echo 'No results match your search, please try again';
}
?>
And here is the CSS:
<style>
#boxes {
padding: 10px;
margin-top: 20px;
margin: 10px;
float: left;
display: block;
}
#results {
width: 212px;
padding: 5px;
background: #E8CF24;
display: block;
overflow:auto;
font-family: Verdana, Geneva, sans-serif;
font-size: 11px;
font-color: #FFF;
border: 2px solid #cccccc;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border-radius: 7px;
-moz-box-shadow: 2px 2px 2px #cccccc;
-webkit-box-shadow: 2px 2px 2px #cccccc;
box-shadow: 2px 2px 2px #cccccc;
}
#table {
margin-top: 10px;
width: 200px;
padding: 3px;
background: #FFF;
display: block;
overflow:auto;
border: 2px solid #cccccc;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border-radius: 7px;
-moz-box-shadow: 2px 2px 2px #cccccc;
-webkit-box-shadow: 2px 2px 2px #cccccc;
box-shadow: 2px 2px 2px #cccccc;
}
.image {
margin-left: 28px;
margin-bottom: 0px;
margin-top: 5px;
}
a:link {
color: #000423;
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
}
</style>
I have tried to edit it with the CSS but I can change the position and padding, margins and so on forth. But I can't get them to align next to each other.
Anyone able to help? Thanks in advance :)
In your css add this to your #results selector.
#results {
float:left
}
EDIT: Sorry that was not the correct answer. Delete the above code and look into thee below code.
Replace the while loop with the below code.
EDIT: Dont forget to initialize the $count variable. ($count = 0;)
Just copy-paste the code and it should work for you.
$count = 0;
while ($row = mysql_fetch_array($r_query))
{
$t = $count%3;
echo ($t==2) ? '<div id="results">' : '<div id="results" style="float:left">';
echo '<p class="image">
<img src=" '. $row['imagename'] . '" width="150" length="80">
</p>';
echo '<div id="table"><br />
<strong> Tool Code: </strong> '. $row['toolcode'];
echo '<br /><strong> Description: </strong> '. $row['description'];
echo '<br /><strong> Tray range: </strong> '. $row['trayrange'];
echo '<br /><strong> Tray type: </strong> '. $row['traytype'];
echo '<br /><strong> Tray size: </strong> '. $row['traysize'];
echo '<br /><strong> Tray shape: </strong> '. $row['trayshape'] . '</div>' . '<br />';
echo 'Enquiry Page <br />' .
'Back to Search';
echo '</div>';
$count++;
}
This is what i get. I didnt use the css file.
Related
I have a script that checks for dupe values in db and loops through the result and echoes the value using json. However, it is only displaying 1 record instead of 3 which is being sent to php. I would be grateful if someone could point out my error. Thanks
$boxitems = mysqli_real_escape_string($conn, $_POST['box']);
$array = array();
$array = $boxitems;
foreach ($array as $boxes) {
$sql = "SELECT item FROM act WHERE item = '".$boxes."' GROUP BY item HAVING COUNT(*) > 1";
$result = mysqli_query($conn, $sql) or die('Error selecting item: ' . mysqli_error());
$num_rows = mysqli_num_rows($result);
if($num_rows) {
while ($row = mysqli_fetch_array($result)) {
$data[] = $row['item'];
}
echo '<div style="width: 50%; margin-bottom: 20px; border-radius: 5px; border: 1px solid black; background: red; font-size: 16px; color: white; height: 50px; padding: 15px; line-height: 1.3;">';
echo json_encode($data) . ' already exists. Please enter a unique box reference.';
echo '</div>';
exit;
} else {
echo '<div style="width: 50%; margin-bottom: 20px; border-radius: 5px; border: 1px solid black; background: #63c84c; font-size: 16px; color: white; height: 50px; padding: 15px; line-height: 1.3;">';
echo 'No dupes found in database.';
echo '</div>';
exit;
}
}
UPDATED screen shot
Put what your want to echo into a single variable that is declared outside the foreach and concatenate each div (one for each loop your foreach does). And then echo it after the loop.
$boxitems = $_POST['box'];
$insertedItems = array();
$duplicateItems = array();
foreach ($boxitems as $boxes) {
$escapedBoxes = mysqli_real_escape_string($conn, $boxes);
$sql = "SELECT item FROM act WHERE item = '".$escapedBoxes."' GROUP BY item HAVING COUNT(*) > 0";
$result = mysqli_query($conn, $sql) or die('Error selecting item: ' . mysqli_error());
$num_rows = mysqli_num_rows($result);
if($num_rows) {
while ($row = mysqli_fetch_array($result)) {
$duplicateItems[] = $row['item'];
}
}
else
{
$insertedItems[] = $escapedBoxes;
}
}
if(!empty($duplicateItems)) {
echo '<div style="width: 50%; margin-bottom: 20px; border-radius: 5px; border: 1px solid black; background: red; font-size: 16px; color: white; height: 50px; padding: 15px; line-height: 1.3;">';
echo json_encode($duplicateItems) . ' already exists. Please enter a unique box reference.';
echo '</div>';
} else {
echo '<div style="width: 50%; margin-bottom: 20px; border-radius: 5px; border: 1px solid black; background: #63c84c; font-size: 16px; color: white; height: 50px; padding: 15px; line-height: 1.3;">';
echo 'No dupes found in database.<br/>';
echo json_encode($insertedItems) . ' has been entered successfully into the database.';
echo '</div>';
}
EDIT: Updated code considering u_mulder comment.
$boxitems = mysqli_real_escape_string($conn, $_POST['box']);
$array = array();
$array = $boxitems;
foreach ($array as $boxes) {
$sql = "SELECT item FROM act WHERE item = '".$boxes."' GROUP BY item HAVING COUNT(*) > 1";
$result = mysqli_query($conn, $sql) or die('Error selecting item: ' . mysqli_error());
$num_rows = mysqli_num_rows($result);
if($num_rows) {
while ($row = mysqli_fetch_array($result)) {
$data[] = $row['item'];
}
echo '<div style="width: 50%; margin-bottom: 20px; border-radius: 5px; border: 1px solid black; background: red; font-size: 16px; color: white; height: 50px; padding: 15px; line-height: 1.3;">';
echo json_encode($data) . ' already exists. Please enter a unique box reference.';
echo '</div>';
exit;
} else {
echo '<div style="width: 50%; margin-bottom: 20px; border-radius: 5px; border: 1px solid black; background: #63c84c; font-size: 16px; color: white; height: 50px; padding: 15px; line-height: 1.3;">';
echo 'No dupes found in database.';
echo '</div>';
}
exit;
}
An exit inside any function, loop or condition will make the program to go out of it and continue, so it's not iterating through, it's exiting after the first iteration.
This is the php code I am modifying to have a header and a description text box appear above the slider. It works great if there is a header and description set within the slider, but on other pages I just want the image - instead an empty "text box" is displayed as it reads the <h2> and <br> tags.
Is there anyway I can make an if .$item['itemImageTitle'] & .$item['itemTitle'] empty show just the image, if not empty show the boxes too?
css
.nivo-caption h2 {
font-size: xx-large;
color: #fff;
}
.theme-default .nivo-caption {
font-family: inherit;
font-size: 16px;
font-weight: bold;
/* z-index: 20; */
-moz-text-shadow: 1px 1px 0 #000;
-webkit-text-shadow: 1px 1px 0 #000;
text-shadow: 1px 1px 0 #000;
position: absolute;
left: 23px;
bottom: 20px;
background: rgba(58, 88, 129, 0.5);
color: #fff;
width: 95%;
z-index: 8;
padding: 5px 10px;
opacity: 1;
overflow: hidden;
display: none;
-moz-opacity: 1;
filter: alpha(opacity=1);
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
php
<div class="slider-wrapper <?php echo "theme-".$theme_title;?>" id="<?php echo "slider-wrapper-".$bID; ?>">
<div id="<?php echo "nivo-slider-".$bID; ?>" class="nivoSlider" style="width: 100% !important;">
<?php
foreach($items as $item) {
echo (strlen($item['itemUrl'])>1) ? '<a href="'.$item['itemUrl'].'">' : '';
echo '<img src="'.$item['itemImageSrc'].'" alt="'.$item['itemImageAlt'].'" title="<h2>'.$item['itemTitle'].'</h2><br>'.$item['itemImageTitle'].'" data-thumb="'.$item['itemImageSrc'].'" >';
echo (strlen($item['itemUrl'])>1) ? '</a>' : '';
}
?>
</div>
</div>
As you said if .$item['itemImageTitle'] & .$item['itemTitle'] empty show just the image. You can try this
<div class="slider-wrapper <?php echo "theme-".$theme_title;?>" id="<?php echo "slider-wrapper-".$bID; ?>">
<div id="<?php echo "nivo-slider-".$bID; ?>" class="nivoSlider" style="width: 100% !important;">
<?php
foreach($items as $item) {
echo (strlen($item['itemUrl'])>1) ? '<a href="'.$item['itemUrl'].'">' : '';
$my_title = "";
if(!empty($item['itemImageTitle']) && !empty($item['itemTitle'])){
$my_title = '<h2>'.$item['itemTitle'].'</h2><br>'.$item['itemImageTitle'].'</h2>';
}
echo '<img src="'.$item['itemImageSrc'].'" alt="'.$item['itemImageAlt'].'" title="'.$my_title.'" data-thumb="'.$item['itemImageSrc'].'" >';
echo (strlen($item['itemUrl'])>1) ? '</a>' : '';
}
?>
</div>
</div>
I am making a radio scheduler. It should show which program is on now.
<?php header('Access-Control-Allow-Origin: *'); ?>
<?php
mysql_connect("localhost", "Dennis", "***") or die(mysql_error());
mysql_select_db("daletnew") or die(mysql_error());
date_default_timezone_set('Europe/Amsterdam');
$day = date('l');
$hour = date('H');
$query = "SELECT time_end FROM shows WHERE day='$day' AND time_start='$hour'";
$result = mysql_query($query);
$query = "SELECT * FROM shows WHERE day='$day' AND time_start='$hour'";
$result = mysql_query($query);
if (mysql_num_rows($result)==0) {
echo '<div id="onair_info" style="position: relative; top: 40px;">';
echo '<br />';
echo '<div class="info_time_time" style="position: relative; left: 4px; color: #2980b9; font-size: 18px; font-family: Roboto; font-weight:300; top: -10px; ">';
echo "FavoriteFM Music";
echo '</div>';
echo '</div>';
} else {
while ($row = mysql_fetch_assoc($result)) {
$show_name = $row['show_name'];
$DJ = $row['DJ'];
$time_start = $row['time_start'];
$time_stop = $row['time_stop'];
$sql1 = "SELECT * FROM DJ WHERE DJ='$DJ'";
$result1 = mysql_query($sql1);
while($info1 = mysql_fetch_array($result1))
{
$image_url = $info1['image_url'];
}
echo '<div id="circle" style="position: relative; top: 40px; left: 175px; width:50px;height:50px; border-color:#00aeff; border-radius:50px; line-height:100px;text-align:center; background-repeat: no-repeat; background-image: url(' . $image_url . ');"></div>';
echo '<div id="onair_info" style="position: relative; top: 0px;">';
echo '<div class="info_time_LIVE" style="position: relative; color: #2980b9; font-size: 12px; font-family: Roboto;top: -12px;left: 20px;">';
echo 'LIVE </div>';
echo '<div class="info_time_time" style="position: relative; left: 60px; color: #2980b9; font-size: 12px; font-family: Roboto;top: -26px;">';
echo $time_start;
echo '</div>';
echo '<div class="arrow_to_right" style="position: relative; width:15px; top: -40px;left: 80px;height:15px; background-repeat: no-repeat; background-image:url(\'http://test.favoritefm.com/wp-content/themes/FavoriteFM/img/arrow_to_right.png\')"></div>';
echo '<div class="info_time_time" style="position: relative; left: 100px; color: #2980b9; font-size: 12px; font-family: Roboto;top: -55px;">';
echo $time_stop;
echo '</div>';
echo '<br />';
echo '<div class="info_show" style="position: relative; top: -57px; left: 20px; color: #2980b9; font-size: 14px; font-family: Roboto;">';
echo '<div class="dj_name" style="font-size: 15px; font-family: Roboto; font-weight: bold";>';
echo $DJ;
echo '</div>';
echo '<br />';
echo '<div class="show_name" style="font-size: 14px; font-family: Roboto;position: relative;top: -15px">';
echo $show_name;
echo '</div>';
echo '</div>';
echo '</div>';
}
}
?>
Obviously, it shows shows that exactly last one hour. But now I have shows that start at 12 and end at 16. I don't know where to start or how to do it. How can I get the script to show a radio show between 12 and 16? I have the beginning and end time in the table als time_start and time_stop.
Try changing your second SQL line to this:
$query = "SELECT * FROM Shows WHERE day='$day' AND time_start<=$hour AND time_stop>$hour";
$result = mysql_query($query);
You can completely remove the first SQL query and keep all the other code the same. It uses SQL comparison operators that will return the radio show if the current hour is between the start and end hours. Using your example (12-16 hours), 12:15 and 15:50 would return the show, but 11:55 and 16:05 would not.
Edit: Please ensure that time_start and time_stop are SQL Int type, and that $hour is an Int. The comparison operators can't compare strings.
I am creating a search form for a packaging database and I have used CSS to style the HTML form that calls to the PHP page. I want to be able to style all the results from the PHP page using the same kind of CSS that styles the search form, as the PHP continues to echo the results as separate elements I want all of them to be displayed in separate little boxes. Is it as simple as I think it is e.g. just surrounding the PHP with tags? As I am trying that currently but it doesn't seem to work.
<body>
<?php
$con = mysql_connect ("localhost", "root", "");
mysql_select_db ("delyn_db", $con);
if (!$con)
{
die ("Could not connect: " . mysql_error());
}
$descrip = mysql_real_escape_string($_POST['descrip']);
$depth = mysql_real_escape_string($_POST['depth']);
$varWidth = mysql_real_escape_string($_POST['traywidth']);
$varHeight= mysql_real_escape_string($_POST['trayheight']);
$varRange = mysql_real_escape_string($_POST['trayrange']);
$varType = mysql_real_escape_string($_POST['traytype']);
$varShape = mysql_real_escape_string($_POST['trayshape']);
$varImage = mysql_real_escape_string($_POST['imagename']);
if (isset($varHeight) && !empty($varHeight)) {
$low = ($varHeight."00");
$high = ($varHeight."99");
} else {
$low = ("000");
$high = ("999");
}
if (isset($varWidth) && !empty($varWidth)) {
$min = ($varWidth."00");
$max = ($varWidth."99");
} else {
$min = ("000");
$max = ("999");
}
$sql = "SELECT * FROM delyn WHERE
description LIKE '%".$descrip."%'
AND trayrange LIKE '%".$varRange."%'
AND traytype LIKE '%".$varType."%'
AND trayshape LIKE '%".$varShape."%'
AND traywidth BETWEEN '".$min."' AND '".$max."'
AND trayheight BETWEEN '".$low."' AND '".$high."' ";
?>
while ($row = mysql_fetch_array($r_query))
{
echo '<p class="results">';
echo '<br /><img src=" '. $row['imagename'] . '" width="120" length="50">';
echo '<br /><strong> Tool Code: </strong> '. $row['toolcode'];
echo '<br /><strong> Description: </strong> '. $row['description'];
echo '<br /><strong> Tray range: </strong> '. $row['trayrange'];
echo '<br /><strong> Tray type: </strong> '. $row['traytype'];
echo '<br /><strong> Tray size: </strong> '. $row['traysize'];
echo '<br /><strong> Tray shape: </strong> '. $row['trayshape'] . '<br />' . '<br />' . '</p>';;
}
if (mysql_num_rows($r_query) <= 0){
echo 'No results match your search, please try again';
}
?>
</body>
CSS (For the HTML form, I want the same attributes for the Form div tag to work for the results):
#charset "UTF-8";
/* CSS Document */
body {
}
.results {
width: 190px;
padding: 10px;
background: #E8CF24;
overflow:auto;
display:block;
font-family: Verdana, Geneva, sans-serif;
font-size: 11px;
border: 1px solid #cccccc;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border-radius: 7px;
-moz-box-shadow: 2px 2px 2px #cccccc;
-webkit-box-shadow: 2px 2px 2px #cccccc;
box-shadow: 2px 2px 2px #cccccc;
}
Now EDITED.
Instead of using breaks use paragraph tags.
<p><?php echo $row['imagename']; ?></p>
For example. Then you can assign classes to the paragraph tags.
So if you want to assign a class for each part just have:
<p class="image_name_class"><?php echo $row['imagename']; ?></p>
<p class="tool_code_class"><?php echo $row['toolcode']; ?></p>
Or in a form:
<label class="control-label" for="input01">Tool Code</label>
<input class="input" ID="tool_code" runat="server"><?php echo $row['toolcode']; ?></input >
Though where you have .input in that CSS you can just have input rather than .input that way you don't have to assign a class to your inputs it will be automatically.
I've searched and can't seem to make sense of the answers I've found. Grateful for any help!!
Goal: Reveal selected message detail in section#details below the listed message headers in section#info.
Problem:
The following code alerts a result but won't fadeIn();, (or show();, or ...anything).
The following code is only grabbing the value of the last result in the PHP while loop.
php/html/jquery/javascript:
<section id="info">
<?php
$user = $session->username;
$q = sprintf("SELECT * FROM mail WHERE UserTo = '%s' ORDER BY SentDate DESC",
mysql_real_escape_string($user));
$getMail = mysql_query($q, $link) or die(mysql_error());
if(mysql_num_rows($getMail) == 0) {
echo "<p>you have no mail</p>";
}
else {
?>
<form id="inbox" class="mail">
<fieldset>
<ul>
<li style="border: 2px solid purple; width: 100%;">
<span style="display: inline-block; border: 1px solid black; width: 8%; margin-left: 13%;">Status</span>
<span style="display: inline-block; border: 1px solid black; width: 15%;">From</span>
<span style="display: inline-block; border: 1px solid black; width: 45%;">Subject</span>
<span style="display: inline-block; border: 1px solid black; width: 16%;">Time</span>
</li>
<?php
while($mail = mysql_fetch_object($getMail)) {
$status = $mail->status;
$mailId = $mail->mail_id;
$from = $mail->UserFrom;
$subject = $mail->Subject;
$received = $mail->SentDate;
$theMessage = $mail->Message;
?>
<li class="outerDiv" style="border: 2px dotted purple;">
<button style="display: inline;" class="viewButton">View</button>
<button style="display: inline;">Delete</button>
<?php
echo "<span style='border: 1px solid red;'>" . $mail_id . "</span>";
echo "<span style='display: inline-block; width: 8%; border: 1px solid red;'>" . $status . "</span>";
echo "<span style='display: inline-block; width: 15%; border: 1px solid red;'>" . $from . "</span>";
echo "<span style='display: inline-block; width: 45%; border: 1px solid red;'>" . $subject . "</span>";
echo "<span style='display: inline-block; font-size: x-small; width: 17%; border: 1px solid red;'>" . $received . "</span>";
?>
</li>
<?php }
} ?>
</ul>
</fieldset>
</form>
</section>
<section id="details">
<div class="theMessage" style="display: none;"><?php echo $theMessage; ?></div>
<script type="text/javascript">
$(document).ready(function() {
$(".outerDiv").click(function(e) {
if($(e.target).is(".viewButton")) {
alert($(document).find(".theMessage").text()); //this works
$(document).find(".theMessage").text().fadeIn(1000); //this doesn't work
var theMessage = $(document).find(".theMessage").text();
theMessage.fadeIn(1000); //this doesn't work
}
});
return false; (sometimes prevents default..sometimes not?
});
</script>
</section>
p.s. the crazy colors and borders are/were for temp layout purposes. also, the delete button will obviously have functionality... once I can figure this out.
Instead of
$(document).find(".theMessage").text().fadeIn(1000);
use
$('.theMessage').fadeIn(1000);
Starx is correct, but I figured I'll give an explanation as well.
$('.theMessage').fadeIn(1000);
In case you don't understand why, take a look at http://api.jquery.com/text/ . The text() method only returns a string, not an actual HTML element that you can manipulate (in this case fadeIn). So text() is good to get or set the contents of an element, but to animate you need to call the methods directly on the $('.theMessage') element.