PHP "Placeholder" Results-Tabs - php

Building an app that queries database for optical images for patients. The results are sorted by date and organized into tabs. Each patient could have any number of tabs based on their history of doctor visits. My tabs are organized horizontally at the top of my page. When there is only one row worth of results tabs (no matter how many) the page looks fine. However, if the amount of tabs exceeds the amount that can be contained in the first row (about 10), a second row starts. This creates a gap between my results tabs and the div that holds their contents.
What I want to know is if it would be possible to create extra "placeholder" tabs that could fill this empty space and how I might go about doing that. Obviously every patient's results are different so I would need to make enough extra tabs to fill any sized gap.
CODE:
<ul class="tabs" id="results">
<?php
if(isset($_GET['id']) && $_GET['id'] != '')
{
$id = $_GET['id'];
$query = "select * from SHOT join VISIT on VISIT.ID=SHOT.VISIT_ID JOIN PATIENT ON SHOT.PATIENT_ID=PATIENT.ID where SHOT.PATIENT_ID=
" . $id . " order by VISIT.VISIT_DATE DESC;";
$res = mysql_query($query);
//Here we count the number of returned rows. If it returned nothing then it will store 0.
$count = mysql_num_rows($res);
$i = 0;
$j = 1;
if($count > 0)
{
$previous_vdate = '';
while($row = mysql_fetch_array($res))
{
$id = $row['ID'];
$vdate = $row['VISIT_DATE'];
$img = $row['IMG_FILENAME'];
$subdir = $row['SUBDIR'];
$subsubdir = $row['SUBSUBDIR'];
if ( strcmp("$vdate", "$previous_vdate") != 0)
{
$formatted_vdate = explode(" ", $vdate);
$formatted_vdate = explode("-", $formatted_vdate[0]);
$visit_date = $formatted_vdate[1] . "-" . $formatted_vdate[2] . "-" . $formatted_vdate[0];
if ($j == 1)
{
echo "<li class='active' rel='tab" . $j . "'>" . $visit_date . "</li>";
}
else
{
echo "<li rel='tab" . $j . "'>" . $visit_date . "</li>";
}
$previous_vdate = $vdate;
$j++;
}
$i++;
}
}
else
{
echo "<div id='no_result'>No result found !</div>";
}
echo "<li rel='tab" . $j . "'>All Dates Combined</li>";
}
else
{
echo "<p>Something's Broke</p>";
}
?>
All help is appreciated. If there's any other info I can add let me know... I'll be in front of the computer for the next several hours, checking/refreshing this page.
Generated HTML:
<ul id="results" class="tabs"><li class="active" rel="tab1">
04-23-2012
</li><li rel="tab2">
04-10-2012
</li><li rel="tab3">
03-05-2012
</li><li rel="tab4">
06-06-2011
</li><li rel="tab5">
12-14-2010
</li><li rel="tab6">
12-14-2009
</li><li rel="tab7">
12-15-2008
</li><li rel="tab8">
12-12-2007
</li><li rel="tab9">
02-07-2007
</li><li rel="tab10">
11-01-2006
</li><li rel="tab11">
11-03-2005
</li><li rel="tab12">
03-13-2002
</li><li rel="tab13">
All Dates Combined
</li><li>
Here is the screen shot: http://imgur.com/5lYpj5Y

If you are allowed to use Javascript I can recommend you to use auto-fit:
Demo:
http://pmbennett.net/demos/autofit-tabs.html (try it by changing the size of your browser window)
Source:
http://pmbennett.net/2010/03/26/auto-fit-tabs/
Disadvantage: Not a CSS-only solution
Personally I think a tab without function, just to fill the empty space, would confuse users. I think users would click it and nothing would happen. Maybe it is also easier to give the empty space a lighter (grey?) background.

Related

How to change the button text in the SQL in a PHP code?

The following is my code:
<?php $result = mysql_query("SELECT * FROM pm_categories WHERE parent_id = 512 ORDER BY tag desc"); ?>
<?php while($row = mysql_fetch_assoc($result)) { ?>
<a class="button button-blue plus20 category" href="https://www.parvizshahbazi.com/ganj_videos/app/listvideos.php?range=<?php echo $row['tag']; ?>"><?php echo str_replace("-", " - ", $row['tag']); ?></a>
<?php } ?>
This is the result:
The buttons have numbers 1-100,101-200 and so on
I was wondering how I can have 801-1000 instead of 801-900. I know that the digits are created from the while loop. Is there anyway to manually create the 801-1000 button?
I tried to manipulate the chart numbers in SQL, yet if 801-900 is manually changed to 801-1000, it gives an error. Because they are in the category of 801-900. What I want is just 801-1000 on the button for 801-1000.
Here is my SQL 'pm_config':
pm_config list
In sum, this is what I want in the end (it is photo-shopped):
What I desire to have in the end
You could, in your 'while' loop, create a specific rule, like this:
while($row = mysql_fetch_assoc($result))
{
// if your loop is treating the 801-900 tag, then just change it to 801-1000
if($row['tag'] == '801-900') { $row['tag'] = '801-1000'; }
echo '<a class="button button-blue plus20 category" href="https://www.parvizshahbazi.com/ganj_videos/app/listvideos.php?range=' . $row['tag'] . '">' . str_replace("-", " - ", $row['tag']) . '</a>';
}

Making a PHP IF Statement to determine if there's any Results from a MySQL Query

I have a website where drinks are sorted by brand and by 'product description' or 'grade'. When visiting a page for a particular drink, amongst other menus one of the menus shows the product description of the current drink (and if clicked on goes to a page showing other drinks from different brands with the same product description) and on hover over shows drinks from the same brand with a different product description (the hover effects are done with simple CSS).
This all works fine - however some brands only have a single product, meaning that the menu appears but with zero height (except for the border) and no data in it, which doesn't look good. So what I want is an IF statement that'll detect whether there are any results from the MySQL query and use different CSS depending on the result - however I just can't seem to find a way that works.
($Brand and $ProductDescription are defined earlier, and refer to the current drink)
<?php
$sql = "
SELECT DISTINCT
ProductDescription
FROM
WebDatabaseText
WHERE
Brand='$Brand' AND
ProductDescription<>'$ProductDescription' AND
Hide=0 AND
Language='$Language' AND
Website='$Website' AND
ProductDescription <> '(brand notes)'
ORDER BY
ProductDescription
";
$result = $conn->query($sql);
If there's at least one result:
echo "<ul id='nav' class='drop'>
<li><a href='/english/grades/?Grade=". $ProductDescription . "'>" . $ProductDescription . "</a> ";
echo " <ul>";
while($row = $result->fetch_assoc()) {
echo "<li><a href='/english/products/?Brand=" . $Brand . "&ProductDescription=". $row["ProductDescription"] . "'>" . $row["ProductDescription"] . "</a> </li>";
}
echo " </ul> </li> ";
echo " </ul>";
If there's nothing:
echo "<ul id='nav' class='drop'>
<a href='/english/grades/?Grade=". $ProductDescription . "'>" . $ProductDescription . "</a> </ul>
?>
Number of found records is in mysqli_num_rows function.
if ($result->num_rows > 0) {
while (...) {
...
}
} else {
echo 'Nothing found';
}
Try
if ($result->num_rows > 0) {
//your while loop here
} else {
//do something
}

Need ideas in proper html rendering with php

I have constructed an SQL query to lay out some info on a web page. The query works well. The problem is with each iteration of while loop a CSS class needs to be auto-incremented by 1.
<div class="related-item item1">
'item1' should become 'item2' in the next iteration and so on. Can you give me something ideas how to do it?
<?php
//Construct the SQL query code
$rel = "SELECT entries.*, images.name
FROM entries, images
WHERE entries.id = blog_id
ORDER BY dateposted DESC
LIMIT 0, 3;";
//Send the query to the MySQL server
$result = mysql_query($rel);
//Pull the row as an associative array
while ($row = mysql_fetch_assoc($result)) {
echo '<div class="related-item item1">
<div class="thumbnail-wrapper">';
echo '<img src="./images/' . $row['name'] . '" alt="How SHAPE Reader Caitlin Flora Lost 182 Pounds"/></div>
<h4 class="related-article-title">
' . $row['subject'] . '
</h4>
</div>';
} //End of while loop
?>
Just keep a counter variable going
$cnt = 1;
while(fetch from db) {
echo "<a class='foo{$cnt}'>click me</a>";
$cnt++;
}
which produces
<a class='foo1'>click me</a>
<a class='foo2'>click me</a>
<a class='foo3'>click me</a>
etc...
but generally this sort of thing is NOT necessary for CSS. You'd have to create a css rule for EVERY one of those <a> elements being created, which gets incredibly ugly and repetitive. There is nth-child support in CSS, so you can write rules which "modify" themselves based on which child an element is (1st, 2nd, ... Nth).
Add an integer and increment it...
<?php
//Construct the SQL query code
$rel = "SELECT entries.*, images.name
FROM entries, images
WHERE entries.id = blog_id
ORDER BY dateposted DESC
LIMIT 0, 3;";
//Send the query to the MySQL server
$result = mysql_query($rel);
$i = 1;
//Pull the row as an associative array
while ($row = mysql_fetch_assoc($result)) {
echo '<div class="related-item item{$i}">
<div class="thumbnail-wrapper">';
echo '<img src="./images/' . $row['name'] . '" alt="How SHAPE Reader Caitlin Flora Lost 182 Pounds"/></div>
<h4 class="related-article-title">
' . $row['subject'] . '
</h4>
</div>';
$i++;
} //End of while loop
?>

How to make a style list out of database information

I realize this isn't the typical question, and I will delete it tonight as to not take up space with a non-code error question, but I really need some help. I am trying to pull information from the question database and create a list of questions organized by the question title. When the user click on the question title, it brings them to the next page according to the question_id.
I posted the code for how the list of questions are currently being displayed, but I can't figure out how I would style them to make it actually look appealing. Would I use say 10 div tags with 10 different id's that all specify the background, and distance from the top? or would I use a table? or is there something else I could use?
I'm new with php and html, and I really don't know many ways to display information that is being pulled from the database....
Current_questions.php
<?php
$i = 0;
$str = "";
$sql = "SELECT * FROM questions";
$result = mysql_query ($sql, $conn) or die(mysql_error());
if (mysql_num_rows($result) >= 0)
{
while ($row = mysql_fetch_array($result, MYSQL_ASSOC) and $i<10 )
{
$i++;
$str .= $i . ". ";
$str .= "<a href='show_question2.php?question_id=" . $row["question_id"] . "'>"
. $row["title"] . "</a> <br> ";
}
print $str;
}
?>
This code currently just prints a list of the title's, and that is not ideal. Thanks!
im not looking for how to code it, just suggestion on best way. Simple answer of a couple of words is all i am looking for –
It really helps to learn some CSS
$toggle = false;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC) and $i<10 )
{
$i++;
$str .= $i . ". ";
$toggle = !$toggle;
if($toggle)
$style = "background: Grey;";
else
$style = "background: White;";
$str .= "<a style='padding: 10px;$style' href='show_question2.php?question_id=" . $row["question_id"] . "'>"
. $row["title"] . "</a> <br> ";
}
Start with the HTML entity which best describes what you are doing. To me that sounds like a list. Now decide if it is an ordered or unordered list. If unsure go with u-ordered
You'll probably want your html to end up something like:
<ul>
<li><a href='show_question2.php?question_id=1'>Question 1 Title</a></li>
<li><a href='show_question2.php?question_id=2'>Question 2 Title</a></li>
<li><a href='show_question2.php?question_id=3'>Question 3 Title</a></li>
</ul>
Now look around the internet for one of the many articles on styling a list.
Here are 3 to start you off:
http://www.alistapart.com/articles/taminglists/ -- I'm a big fan of these guys
http://www.webreference.com/programming/css_style2/index.html
http://www.marcofolio.net/css/8_different_ways_to_beautifully_style_your_lists.html
A real quick and dirty examples with lists

PHP/MYSQL populate dropdown sorted by query results

What I'd like is to create a new unordered list for each new value in a mysql result column.
My query looks like this and i'm throwing it into a data array:
$connection = dbconnect();
$getusers = "SELECT users.usr_id, users.usr_firstname, users.usr_lastname, user_groups.group_name FROM users INNER JOIN user_groups ON users.usr_group = user_groups.group_id ORDER BY group_name ASC, users.usr_firstname ASC, users.usr_lastname ASC";
$result = mysql_query($getusers);
$data_array = array();
while($data = mysql_fetch_array($result)){
$data_array[] = $data;
}
Now I need to display that data so that each new user_group is an unordered list, and each row with that same group, comes up as a list item of that unordered list.
it's very similar to this question ( PHP/MySQL Query Results ), but i'm having trouble getting the closing ul's in the right place. Here's my code for outputting, though I know it's wrong because the li's aren't really children of the ul's.
$previousgroup = "";
foreach($data_array as $users){
if($users['group_name'] != $previousgroup){
echo "<ul class=\"group\">" . $users['group_name'] . "</ul>";
}
else{
echo "<li id=\"m" . $users['usr_id'] . "\"><h4>" . $users['usr_firstname'] . " " . $users['usr_lastname'] . ", " . $users['cred_name'] . "</h4></li>";
}
}
Is there a more efficient way of doing this? Thanks for your help.
You could change the while loop this way:
$data_array = array();
while($data = mysql_fetch_array($result)){
$data_array[$data['group_name']][] = $data;
}
and you would get an array that contains your group_name's as index of other arrays which contain your data. To create the list, you could do the following:
<ul>
<?php
foreach ($data_array as $temp_key => $temp_array)
{
?>
<li>
<?php echo $temp_key; ?>
<ul>
<?php
foreach ($temp_array as $datum)
{
echo ("<li>" . $datum['usr_firstname'] . "</li>";
}
?>
</ul>
</li>
<?php
}
?>
</ul>
Hope it works for you
if($users['group_name'] != $previousgroup){
echo "</ul><ul class=\"group\"><li>" . $users['group_name'] . "</li>";
}
echo "<li id=\"m" . $users['usr_id'] . "\"><h4>" . $users['usr_firstname'] . " " . $users['usr_lastname'] . ", " . $users['cred_name'] . "</h4></li>";
The code in your loop should look like this, and you need to open and close a <ul> from outside the loop.
echo '<ul>';
foreach () { // here is the loop }
echo '</ul>';
THis is doing it the "dirty" way with printing out as you go, at least.
The way I would do it would be to build a 2D array indexed first by group_name and then by user ID. It would mean making two passes at the data as a second loop would be needed to display the data, but generally speaking you're not going to feel the difference.

Categories