PHP - Listing Active Users.
Morning(at least for me anyway) All,
I am currently integrating a facebook/style chat system into my webpage. I am going to build the active user list myself but need a little guidance on how to list my users which are online and how to detect when the have gone. When my users login i store only their userid in a session like many login systems. When they login i could simply add their name to a active_users table, but how would i detect whether they are still alive? Any help would be great. Thanks Sam Similar TutorialsHello
I am trying to work out how many regular users I have to my site and how long those users tend to be users..
So, I have a table that logs every time a user visits my site and logs in, it stores the date / time as a unix timestamp and it logs their user id.
I started by getting the id's of any user who logs in more than 5 times in a specified period, but now I want to extend that...
SELECT userID as user, count(userID) as logins FROM login_history where timestamp > UNIX_TIMESTAMP('2014-06-01 00:00:00') and timestamp < UNIX_TIMESTAMP('2014-07-01 00:00:00') group by user having logins > 5; I just discovered that I have a major security flaw with my website. Anyone who logs in to the website can easily access other users information as well as delete and edit other users information just by changing the ID variable in the address bar. I have user ID Session started on these pages but still people can do anything they like with other users information just by editing the address bar. For example if your logged in in the address bar of www.mywebsite.com/delete_mystuff.php?id=5 and change the "5" say to a "9" then you will have access to user#9 information. Every important page that I have has this code: Code: [Select] session_start(); if (!isset($_SESSION['user_id'])) { // Start defining the URL. $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. $url .= '/index.php'; ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. } else { //Else If Logged In Run The Script if((isset($_GET['id'])) && (is_numeric($_GET['id']))) { $id = (int) $_GET['id']; } elseif ((isset($_POST['id'])) && (is_numeric($_POST['id']))) { $id = (int) $_POST['id']; } else { echo ' No valid ID found, passed in url or form element'; exit(); } What am I doing wrong? Please help if you know how to correct this. Many thanks in advance. Ok so I don't even know where to start with this idea so I thought I would poke around here for some inspiration. On my server I have a Directory. In that directory I have roughly 300 folders with 5,000 files + 1 index.php (so 5,001 files but I want to ignore the index.php in the listings) per directory. Anyway what I am trying to do is list all the files and load them into a database. What my ideal goal would be is device a script that I would put in the root directory with the 300 or so subdirectories and let it run through the directories automatically one by one, listing all the files in them and then storing them in the database. I'd break it down more but that part I can figure out on my own cause I do want to do more than just store the file names and corresponding directory its in in the DB. My issue is I can find anything or figure anything out that will cycle through all directories, thats what I need to figure out first. I am trying to have an event with each performance listed for the event underneath. I have worked with the MySQL Forum and have gotten to the point where my coding for MySQL is complete, but it still will not work. I was told from the MySQL Forum group that I need to now post these in this forum... Here's how I tried the coding: Code: [Select] <p class="categoryHeader">Theatre</p><?php $last_eventtitle = NULL; // remember the last EventTitle while ($Row = mysqli_fetch_assoc($TheatreResult)){ $eventtitle = $Row['EventTitle']; if($last_eventtitle != $eventtitle){ // a new or the first EventTitle was found echo '<p>'; if($Row['Ranking']<10){ echo '<img src="http://www.myalaskacenter.com/images/logos/acpa/weblogo-small_nowords.jpg" alt="Alaska Center for the Performing Arts" width="80" height="80" border="0" align="right">'; } if ($Row['FreeEvents']==TRUE){ echo '<img src="http://www.myalaskacenter.com/images/free.gif" alt="Free Event" width="67" height="64" align="right" border="0">'; } echo '<a href="' . $Row['ShoWareEventLink'] . '"><img src="https://alaskapac.centertix.net/UPLImage/' . $Row['thumb'] . '" alt="' . $Row['EventTitle'] . '" title="' . $Row['EventTitle'] . '" align="left" border="0" style="padding-right:5px"><span class="Heading3_blue"><br />' . $Row['EventTitle'] . '</span>'; echo '<br />Presented by <a href="' . $Row['website'] .'" target="_blank">' . $Row['Presenter'] . '</a><br />'; if($last_eventtitle != NULL){ // not the first EventTitle, close out the previous section echo '<br />'.date("l, F j, Y", strtotime($Row['startDateTime']). ' at ' . date("g:i a", strtotime($Row['startDateTime']))).' - <a href="'.$Row['VenueSite'].'" target="_blank">'.$Row['VenueName'].'</a>'; } $last_eventtitle = $eventtitle; // save the new EventTitle // output the heading/start a new section echo '<br />'.date("l, F j, Y", strtotime($Row['startDateTime']). ' at ' . date("g:i a", strtotime($Row['startDateTime']))).' - <a href="'.$Row['VenueSite'].'" target="_blank">'.$Row['VenueName'].'</a>'; echo '<br /><br /></p><hr>'; } } ?> Now it lists the first performances correctly; although it does NOT list the correct number of performances and the first performance is sometimes listed twice -- so almost there. See webpage http://www.myalaskacenter.com/centermail/_upcomingevents.php. For example, Anchorage Youth Symphony only has one performance, but it lists 2; while It's a Wonderful Life has 17 performances, but it lists only 2. What am I doing wrong still? Hey guys I have found this peice of code and messed around with it. I got it to work with Thickbox and I would like to know how to seperate my images aka files to every 4th column. Heres the code I found and tweaked. The images would look great if it was every 4th column they break. Also where would I place he echo command if I want it to display information about that image. Heres the code... Code: [Select] <? /** * Change the path to your folder. * * This must be the full path from the root of your * web space. If you're not sure what it is, ask your host. * * Name this file index.php and place in the directory. */ // Define the full path to your folder from root $path = "images/default/"; // Open the folder $dir_handle = @opendir($path) or die("Unable to open $path"); // Loop through the files while ($file = readdir($dir_handle)) { if($file == "." || $file == ".." || $file == "default.php" ) continue; echo "<a href=\"images/default/$file\" class=\"thickbox\"><img src=\"images/default/$file\" height=\"150\" width=\"150\" border=\"0\"></a>"; } // Close closedir($dir_handle); ?> Hi friends, i want to ask a question. i have two page: "slider.php" and "mansethaberler.php" i extract two data from the database, named "addnews_headline" and "addnews_image" in slider.php. i create link to extracted "headline" from the database. See i added first image. when i clicked the link, link is heading to the second page "mansethaberler.php" and in "mansethaberler.php" with "SELECT" i extract from database "headline" and "image". Now i want to do that. When i clicked the link in "slider.php" i want to listing the image and headline in "mansethaberler.php". "mansethaberler.php" <?php $veri = $db->query("SELECT * FROM haberlerekle ORDER BY haberekle_id",PDO::FETCH_ASSOC)->fetchAll(); ?> <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12"> <?php foreach ($veri as $haber) { ?> <div style="border:1px solid black; height:50px; background-color:#17a2b8; color:white; line-height:50px; text-align:center;"><?php echo $haber["habereklesayfasi_baslik"]; ?></div> <div class="row no-gutters"> <img class="col-lg-12 mt-2" src="upload/images/<?php echo $haber["haberekle_resim"]; ?>" style="max-height:444px;"> </div> </div> <div class="col-lg-12 ml-auto mt-1 mb-1" style="padding-left:7px;"><?php echo $haber["haberekle_konu"]; } ?></div> "slider.php" <img src="upload/images/<?php echo $row["haberekle_resim"]; ?>" width="832" height="502"> <!-- upload/images/ ile <?php ?> tag'leri arasında boşluk olursa link kırılıyor. Resim çıkmıyor. --> <div class="carousel-caption"> <p><a href="mansethaberler.php"><?php echo $row['haberekle_baslik']; ?></a></p> </div>
Edited August 19, 2020 by CodingStudent i forgot to put the most important codes directory listing: hi guys, im using a PHP script to output a list of documents in different directory's using a single index.php (apart from the style obv), its not a major issue but bugging me as to how to get it to ignore the "up" link for directory navigation. its outputting the below: . .. this is annoying me... is it possible to get it to ignore these and not output them? Code: [Select] <link rel="stylesheet" type="text/css" href="style.css"> <span class="note"> <?php echo "directoryname3"; ?></span> <?php $dir="directoryname3"; if ($dir_list = opendir($dir)) { while(($filename = readdir($dir_list)) !== false) { ?> <p><a href="<?php echo $filename; ?>"><?php echo $filename; ?></a></p> <?php } closedir($dir_list); } ?> <br><br> <span class="note"> <?php echo "<b>directoryname3</B>"; ?></span> <?php $dir="directoryname3"; if ($dir_list = opendir($dir)) { while(($filename = readdir($dir_list)) !== false) { ?> <p><a href="<?php echo $filename; ?>"><?php echo $filename; ?></a></p> <?php } closedir($dir_list); } ?> <br><br> <span class="note"> <?php echo "<b>directoryname3</B>"; ?></span> <?php $dir="directoryname3"; if ($dir_list = opendir($dir)) { while(($filename = readdir($dir_list)) !== false) { ?> <p><a href="<?php echo $filename; ?>"><?php echo $filename; ?></a></p> <?php } closedir($dir_list); } ?> <br><br> <span class="note"> <?php echo "<b>directoryname</B>"; ?></span> <?php $dir="directoryname"; if ($dir_list = opendir($dir)) { while(($filename = readdir($dir_list)) !== false) { ?> <p><a href="<?php echo $filename; ?>"><?php echo $filename; ?></a></p> <?php } closedir($dir_list); } ?> I have a mysql database set up with 4 fields - id, month, day, event. The database will be filled with something like: month=Jan, day=4 and event=Meeting. All are text fields. The display will be Jan. 4: Meeting I can set up the PHP to display the database in a unordered list. The code for this is: <?php $result = @mysql_query("SELECT id, month, day, event FROM homecalendar"); if (!$result) { exit('<p>Error performing query: ' . mysql_error() . '</p>'); } while ($row = mysql_fetch_array($result)) { echo '<li>' . $row['month'] . $row['day'] .': ' . $row['event'] . '</li>' ; } ?> How can I limit the code to display items for only the current month and the next month? Is it possbile to use PHP to list directories outside of the root of the web server - for example c:\images or d:\images? I can use this script to list the files from the root down, but when I change the path to look at something outside the web server directory I get zero results back. Thank you. <?php filesInDir('d:\policy'); function filesInDir($tdir) { echo ("<p><h1>List of files in ($tdir):</h1></p><hr><br />"); $dirs = scandir($tdir); foreach($dirs as $file) { if (($file == '.')||($file == '..')) { } elseif (is_dir($tdir.'/'.$file)) { filesInDir($tdir.'/'.$file); } else { echo $tdir.'/'.$file.' --- '.date("F d Y H:i:s", filemtime('$file'))."<br>"; } } } ?> ok I have a text file that has ids listed each on a new line how can I go about assigning each id to a variable so like 12312412 23432443 34654366 56456345 the variable $ids = all of the ids above one at a time in an array so like $ids[] = 12312412; $ids[] = 23432443; $ids[] = 34654366; $ids[] = 56456345; I am using the following code to list mp3 files from a directory and find out if there is a file for it in mysql if so not to include it in the list. The code below is listing each file twice I only would like them to be listed once. if($_POST['submit'] != 'select') { echo'Choose an mp3 to add information.<p><select name="file">'; $dir = "/uploads/"; $result = mysql_query("SELECT * FROM dj_pool") or die(mysql_error()); $num_rows = mysql_num_rows($result); // Open a known directory, and proceed to read its contents if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { $info = explode(".", $file); if($info[1] == "mp3") { $i = 0; while ($i < $num_rows) { $file2 = mysql_result($result,$i,mp3); if ($file != $file2) { echo "<option value='$info[0]'>$info[0]</option>"; } $i++; } } }closedir($dh);} } print "</select><p><input type=submit value=select name=submit>"; hello guys, I'm stuck he I have a table called customer_messages which has a entryid, custid, fromname, message, flag i have written a script to enter data into this. and another script to count the number of entries in the table. now i want to display entries in the table on to a script what i did was this: flag is by default '0' which mean unread. insertion code: Code: [Select] insert into customer_messages (customer_id,customer_fname,customer_message,flag) values('21','mike','hello!','0') fetching number of unread messages Code: [Select] select count(*) from customer_messages where flag = '0' $q = "select count(*) from customer_messages where flag = '0'"; $w = mysql_query($q); $r = mysql_fetch_array($w); $t = $r[0]; $t now gives me total number of unread messages in the db. now, I want to display these messages on to a page in the following format: ----------------------------------------------------------------------------------------------- | sender | message | mark as read | ----------------------------------------------------------------------------------------------- | name_from_db | message_from_db | check box | ----------------------------------------------------------------------------------------------- | name_from_db | message_from_db | check box | ----------------------------------------------------------------------------------------------- how do I do this? I'm assuming that I have to use a loop here, I put the code in a while loop, but that didnt work out for me. can I use a for loop here? if yes how do i use it? my brain's froze now so, i cant think atm, can someone help me out please? ================================================================================= in short i need the data from database to be listed as listbox control in asp.. is it possible? Right, it's hard to explain, but I'll try my best. Litterally, I have a 'tab' box on my homepage. And a table called 'news'. Now, the table has the rows "shorttitle" "shortstory" and "image" in it. I want the title the three latest titles to be on the three tabs, and the story and image in the respective content areas. (The table auto increments the ID, and so order by ID descending limit of 3 yes?) Now, the code for the tabs is: Code: [Select] <?php $query = "SELECT * FROM news where published = '1' ORDER by id DESC LIMIT 3"; $row_news = mysql_fetch_array($query); ?> <div id="myTabs"> <ul> <li><a href="#firsttab"></a><? echo $row_news['shorttitle']; ?></li> <li><a href="#secondtab">newsID2</a></li> <li id="last"><a href="#thirdtab">newsID3 </a></li> </ul> <div id="firsttab" class="tab_content"> <div class="rafat"> <img src="<? echo $row_news['image']; ?>" /> <p> <? echo $row_news['shortstory']; ?> </p> </div> </div> <div id="secondtab" class="tab_content"> <div class="rafat"> <img src="newsIMAGE2" /> <p> newsSTORY2 </p> </div> </div> <div id="thirdtab" class="tab_content"> <div class="rafat"> <img src="newsIMAGE3" /> <p> newsSTORY3 </p> </div> </div> </div> Now, i've filled in the first tab with the MYSQL queries, but i'm unsure how to fill in the other two, because of the way it's coded.. I can't do a 'repeating' code, because of the IDs of the divs, and the three tabs are bunched together.. Anyone any ideas? Much apreciated. Thanks Luke Sorry for such a simple question, or at least even I think it is. What id like to do is create a function for creating a list of directories/folders in a given base directory and turn the results into an array. It does not have to be recursive. No files. And prefer in alphabetical order BaseUrl = '/'; BaseDir = '/path/to/dir'; For each directory create array as such: Code: [Select] $config['ResourceType'][] = Array( 'name' => '$directory_name', 'url' => $baseUrl . '$directory_name', 'directory' => $baseDir . '$directory_name', 'maxSize' => 0, 'allowedExtensions' => 'htm,html,php,cgi', 'deniedExtensions' => 'asp'); Thanks, and sorry again, Im reading on arrays and how to create the list, figuring out how to put them together is driving me nuts I got myself wrapped up in something I can't get figured. In the following code, I would like to order the list of properties ("<div class="property">") by the "$pr_street" variable. Any help is appreciated. Thanks, <?php /////////////// SEO /////////////// $keywords = ""; $description = ""; /////////////// DB Connection /////////////////// include('../includes/connect.php'); include('../includes/login.php'); if(isset($_GET['delete'])){ $del_id = $_GET['delete']; $sel_del_imgs_q = "SELECT * FROM pr_imgs WHERE pr_id = '$del_id'"; $pr_img_del_result = mysqli_query($db, $sel_del_imgs_q); while($pr_del_imgs = mysqli_fetch_array($pr_img_del_result)){ $pr_del_img_id[] = $pr_del_imgs['pr_img_id']; $pr_del_img_path_xl[] = $pr_del_imgs['pr_img_path_xl']; $pr_del_img_path_l[] = $pr_del_imgs['pr_img_path_l']; $pr_del_img_path_m[] = $pr_del_imgs['pr_img_path_m']; $pr_del_img_path_s[] = $pr_del_imgs['pr_img_path_s']; $pr_del_img_path_xs[] = $pr_del_imgs['pr_img_path_xs']; } for($i = 0; $i < count($pr_del_img_id);$i++){ if(!empty($pr_del_img_path_xl[$i])){ unlink('..'.$pr_del_img_path_xl[$i]); } if(!empty($pr_del_img_path_l[$i])){ unlink('..'.$pr_del_img_path_l[$i]); } if(!empty($pr_del_img_path_m[$i])){ unlink('..'.$pr_del_img_path_m[$i]); } if(!empty($pr_del_img_path_s[$i])){ unlink('..'.$pr_del_img_path_s[$i]); } if(!empty($pr_del_img_path_xs[$i])){ unlink('..'.$pr_del_img_path_xs[$i]); } } $dir_to_remove = dirname(getcwd()).'/images/properties/'.$del_id; rmdir($dir_to_remove); $delete_query = "DELETE property, pr_imgs FROM property LEFT OUTER JOIN pr_imgs ON property.pr_id = pr_imgs.pr_id WHERE property.pr_id = '$del_id'"; $deleted = mysqli_query($db, $delete_query); if($deleted){ header('Location:index.php'); //print $delete_query; } } $sel_pr_type = 1; // 1 = For Rent Residential, 2 = For Rent Commercial, 3 = For Sale $pr_sel_query = "SELECT * FROM property LEFT OUTER JOIN pr_imgs ON property.pr_id = pr_imgs.pr_id AND pr_imgs.pr_img_count = '0' ORDER BY property.pr_live DESC, property.pr_modified DESC"; $result = mysqli_query($db,$pr_sel_query); while($pr_row = mysqli_fetch_array($result)){ $pr_id[] = $pr_row[0]; $pr_type[] = $pr_row['pr_type']; $pr_live[] = $pr_row['pr_live']; $pr_title[] = $pr_row['pr_title']; $pr_street[] = $pr_row['pr_street']; $pr_city[] = $pr_row['pr_city']; $pr_state[] = $pr_row['pr_state']; $pr_zip[] = $pr_row['pr_zip']; $pr_price[] = $pr_row['pr_price']; $pr_bedroom[] = $pr_row['pr_bedroom']; $pr_bathroom[] = $pr_row['pr_bathroom']; $pr_size[] = $pr_row['pr_size']; $pr_img_path_s[] = $pr_row['pr_img_path_s']; } include('../includes/head.php'); include('../includes/header.php'); ob_end_flush(); // ob_start() in /includes/login.php ?> <div class="content"> <div class="hldr"> <?php if($loggedin){ ?> <div class="left"> <h2><a href="/admin/">Admin</a></h2> <?php for($i = 0; $i < count($pr_id); $i++){ if($pr_live[$i] == 1){ $islive[$i] = ' • <span class="live">Live</span>'; } ?> <div class="property"> <div class="thumb"><a href="/property_details.php?property=<?php print $pr_id[$i]; ?>"><img src="<?php print $pr_img_path_s[$i]; ?>" width="100" height="100" /></a></div> <div class="details"> <h4><a href="/property_details.php?property=<?php print $pr_id[$i]; ?>"><?php print $pr_title[$i]; ?></a></h4> <ul> <li>Bedroom: <?php print $pr_bedroom[$i]; ?> • Bathroom: <?php print $pr_bathroom[$i]; ?></li> <li class="adrs"><?php print $pr_street[$i].', '.$pr_city[$i].', '.$pr_state[$i].' '.$pr_zip[$i]; ?></li> <li>Price: $<?php print $pr_price[$i]; ?> 4 • Size: <?php print $pr_size[$i]; ?> sq ft</li> <li><a href="/admin/add-property.php?edit=<?php print $pr_id[$i]; ?>">EDIT</a> • <a href="/admin/index.php?delete=<?php print $pr_id[$i]; ?>" class="red" onclick="return confirm('Are you sure you want to deletet this Property?');">DELETE</a><?php print $islive[$i]; ?></li> </ul> </div> </div> <?php } ?> </div> <div class="right"> <div class="sidebarHome"> <div class="sidebarHome"> <p><strong><a href="/admin/">Admin Home</a></strong></p> <p><strong><a href="add-property.php">Add Property</a></strong></p> <p><strong><a href="for-rent-res.php">Edit Properties for Rent - Residential</a></strong></p> <p><strong><a href="for-rent-com.php">Edit Properties for Rent - Commercial</a></strong></p> <p><strong><a href="for-sale.php">Edit Properties for Sale </a></strong></p> <p><strong><a href="index.php?logout=1">Log Out </a></strong></p> </div> </div> <div class="clear"> </div> </div> <?php }else { ?> <div class="fullpage"> <div class="login"> <?php print $error_msg; ?> <form method="post" action="index.php"> <label>Username:</label> <input type="text" name="user" class="txt" /> <label>Password:</label> <input type="password" name="pass" class="txt" /><br /> <input type="submit" name="login" value="Login" class="submit" /> </form> </form> </div> </div> <?php } ?> </div> <?php include('../includes/footer.php'); ?> I have an ongoing mission to tighten up my code for a directory listing for a non-profit organization. Brief background is - there are multiple "company" members in each County, and usually multiple "contact people" at each company. Also, some companies have "branch" offices, but not all, and most of the branches also have "contact people." I have successfully segregated my code, so that the "listing" work is handled by separate functions. I am trying to work with JOIN queries, and in my first step I am treating the "company" and "branch" listings with separate test code for now, and the branch output is missing the first row of the array that I am creating.
To demonstrate what is happening, I am going to attache a screen shot of the correct results from my query, which starts with a branch called "Louisiana Branch". To see the results of my code, click on this link: http://www.nmlta.org...ew_br_test2.php
And finally, I am including the working portions of my code below... leaving out the connection details, which are not an issue. Just to be clear, I have the exact code structure for a query of the company table, with a similar JOIN, and the listing results of my code do not skip the first row of that array. I must be missing something that should be obvious, but I can't see the problem. I would appreciate any and all help... thanks - Rob
My Code:
<?php function listCompany($row) { echo $row['comp_name'],"<br />"; if (!empty($row['comp_uw'])) { echo $row['comp_uw'],"<br />";} echo "</b>",$row['comp_street'],"<br />"; if (!empty($row['comp_pobox'])) { echo $row['comp_pobox'],"<br />";} echo $row['comp_csz'],"<br />"; echo $row['comp_ph'],"   Fax: ",$row['comp_fx'],"<br />"; if (!empty($row['comp_tfree'])) { echo "Toll Free: ",$row['comp_tfree'],"<br />";} if (!empty($row['comp_email'])) { echo "Email: <a href='mailto:",$row['comp_email'],"'>",$row['comp_email'],"</a><br />";} if (!empty($row['comp_web'])) { echo "<a href='http://",$row['comp_web'],"' target='_blank'>",$row['comp_web'],"</a><br />";} echo "</p>"; } function listBranch($row2) { if (!empty($row2['br_name'])) { echo "<p>     <b>",$row2['branch_name'],"</b><br />";} echo "     ",$row2['br_street'],"<br />"; echo "     ",$row2['br_csz'],"<br />"; echo "     ",$row2['br_ph'],"   ",$row2['br_fx'],"<br /></p>"; } function listContact($row) { if (!empty($row['cont_name'])) { echo "<p>     <b>",$row['cont_name'],"</b>, ",$row['cont_title'],"<br />";} if (!empty($row['cont_email'])) { echo "     Email: <a href='mailto:",$row['cont_email'],"'>",$row['cont_email'],"</a><br />";} echo "</p>"; } function listBranchContact($row2) { if (!empty($row2['cont_name'])) { echo "<p>          <b>",$row2['cont_name'],"</b>, ",$row2['cont_title'],"<br />";} if (!empty($row2['cont_email'])) { echo "          Email: <a href='mailto:",$row2['cont_email'],"'>",$row2['cont_email'],"</a><br />";} echo "</p>"; } // Connection to DB // Retrieve all the data from the "company" table $query2 = "SELECT * FROM branch LEFT JOIN br_contact ON branch.branch_id = br_contact.branch_id WHERE br_county = 'BERNALILLO' ORDER BY branch.comp_name, branch.br_street, br_contact.cont_rank"; $result2 = $mysqli->query($query2) or die($mysqli->error.__LINE__); // Build the $company_array $branch_array = array(); while($row2 = $result2->fetch_assoc()) { $branch_array[] = $row2; } $lastBranch = ''; //Initialize $lastBranch variable // Start building the table to show results echo "<table border='1' cellpadding='10' cellspacing='0' bgcolor='#f0f0f0' style='margin-left:100px; margin-bottom:20px'>"; // Begin the "foreach" loop for rows in the $branch_array foreach($branch_array as $row2) { // Branch Loop // Check if this is a different branch than the last one if ($lastBranch != $row2['branch_id']) { // Loop to check if New Branch // If this is a different branch - change the $lastBranch variable $lastBranch = $row2['branch_id']; echo "<tr><td>"; // List the branch info only if it is not the $lastBranch listBranch($row2); } // End check if New Company loop // List all Contacts in the Branch listBranchContact($row2); } // End Branch Loop echo "</td></tr>"; // Free result set mysqli_free_result($result2); echo "</table>"; mysqli_close($mysqli); ?>Attached Files adminer_bern_br_join_cont.png 450.37KB 0 downloads Hey, I dont know whats wrong but i was hoping someone could take a look at the code and provide some errors that maybe causing this script not to work. I want it to display all the .jpg pictures in thumbnails, it currently does not even get the pictures. code: <?php $pic_listing = mysql_query("SELECT * FROM toplist WHERE id='". $id ."'") or die(mysql_error()); while($serverpic = mysql_fetch_array($pic_listing)) { $servername = $serverpic["servername"]; } $directory = "images/serverpic/" . $servername . ""; $images = glob("" . $directory . "*.jpg"); if(empty($images)) { ?> <div class="highslide-gallery"> <?php foreach($images as $image) { ?> <a href="images/serverpic/<?php echo $servername . "/" . $image; ?>" class="highslide" onclick="return hs.expand(this)"> <img src="images/serverpic/<?php echo $servername . "/" . $image; ?>" alt="Highslide JS" width="100" height="100" title="Click to enlarge" /> </a> <div class="highslide-caption"> <?php } ?> </div> </div> <?php } ?> Hi. I want to create a list of files in a directory. But I don't want all the files to be listed, only .gif, .jpg and .bmp. Does anyone know the PHP code how to do that? (My directory name is 'images' if you need that). Thanks! I have an image gallery with different categories, at the moment the list of categories is simple and just looks like this... General (10) I would like to be able to upload an image when making new categories and display it like this... Can anybody help me with this, here are the pages of code... This is the page that displays the category listing... Code: [Select] <?php include("config.inc.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Roy Neale - Gallery</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="js/prototype.js"></script> <script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script> <script type="text/javascript" src="js/lightbox.js"></script> <link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" /> </head> <body> <div id="head"> <div id="headmain"> <div id="headleft"> <image src="images/bannertop.jpg"> </div> <div id="headright"> <div class="navimage"><image src="images/gallery3.png" onmouseover="this.src='images/gallery2.png'" onmouseout="this.src='images/gallery3.png'"></image><!--start navimage--> </div><!--end navimage--> <div class="navimage"><image src="images/about.png" onmouseover="this.src='images/about2.png'" onmouseout="this.src='images/about.png'"></image><!--start navimage--> </div><!--end navimage--> <div class="navimage"><image src="images/contact.png" onmouseover="this.src='images/contact2.png'" onmouseout="this.src='images/contact.png'"></image><!--start navimage--> </div><!--end navimage--> </div> </div> </div> <div id="mid"> <div id="midleft"> <p> </p> <p> </p> <p> </p> Login <p> </p> <p align="center"><form action="gallery.php" method="post" name="loginform"> <label>Username: </label><input name="username" type="text" class="userpass" size="25" maxlength="25" /> <label>Password: </label><input name="password" type="password" class="userpass" size="25" maxlength="25" /> <p><label></label><input name="submit" type="submit" class="logbutton" value="LOGIN" /></p> </form></p> </div> <div id="midright"> <div id="midrighttop5"> </div> <div id="midrightbottom4"> <?php // initialization $result_array = array(); $counter = 0; $cid = (int)($_GET['cid']); $pid = (int)($_GET['pid']); // Category Listing if( empty($cid) && empty($pid) ) { $number_of_categories_in_row = 3; $result = mysql_query( "SELECT c.category_id,c.category_name,COUNT(photo_id) FROM gallery_category as c LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id GROUP BY c.category_id" ); while( $row = mysql_fetch_array( $result ) ) { $result_array[] = "<a href='gallery.php?cid=".$row[0]."'>".$row[1]."</a> "."(".$row[2].")"; } mysql_free_result( $result ); $result_final = "<tr>\n"; foreach($result_array as $category_link) { if($counter == $number_of_categories_in_row) { $counter = 1; $result_final .= "\n</tr>\n<tr>\n"; } else $counter++; $result_final .= "\t<td>".$category_link."</td>\n"; } if($counter) { if($number_of_categories_in_row-$counter) $result_final .= "\t<td colspan='".($number_of_categories_in_row-$counter)."'> </td>\n"; $result_final .= "</tr>"; } } // Thumbnail Listing else if( $cid && empty( $pid ) ) { $number_of_thumbs_in_row = '1'; $result = mysql_query( "SELECT photo_id,photo_caption,photo_filename FROM gallery_photos WHERE photo_category='".addslashes($cid)."'" ); $nr = mysql_num_rows( $result ); if( empty( $nr ) ) { $result_final = "\t<tr><td>No Gallery found</td></tr>\n"; } else { while( $row = mysql_fetch_array( $result ) ) { $result_array[] = "<a href='".$images_dir."/full_".$row[2]."' rel=\"lightbox\"><img src='".$images_dir."/tb_".$row[2]."' border='3' style='margin: 4px;' bordercolor='silver' alt='".$row[1]."' /></a>"; } mysql_free_result( $result ); $result_final = "<tr>\n"; foreach($result_array as $thumbnail_link) { if($counter == $number_of_thumbs_in_row) { $counter = 1; $result_final .= "\n</tr>\n<tr>\n"; } else $counter++; $result_final .= $thumbnail_link; } if($counter) { if($number_of_photos_in_row-$counter) $result_final .= "\t<td colspan='".($number_of_photos_in_row-$counter)."'> </td>\n"; $result_final .= "</tr>"; } } } // Full Size View of Photo else if( $pid ) { $result = mysql_query( "SELECT photo_caption,photo_filename FROM gallery_photos WHERE photo_id='".addslashes($pid)."'" ); list($photo_caption, $photo_filename) = mysql_fetch_array( $result ); $nr = mysql_num_rows( $result ); mysql_free_result( $result ); if( empty( $nr ) ) { $result_final = "\t<tr><td>No Photo found</td></tr>\n"; } else { $result = mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes($cid)."'" ); list($category_name) = mysql_fetch_array( $result ); mysql_free_result( $result ); $result_final .= "<tr>\n\t<td> <a href='gallery.php'>Categories</a> > <a href='gallery.php?cid=$cid'>$category_name</a></td>\n</tr>\n"; $result_final .= "<tr>\n\t<td align='center'> <br /> <img src='".$images_dir."/".$photo_filename."' border='0' alt='".$photo_caption."' /> <br /> $photo_caption </td> </tr>"; } } // Final Output echo <<<__HTML_END <table width='100%' border='0' align='left' style='margin: 6px;' style='padding: 5px;'> $result_final </table> </div> </div> </div> <div id="foot"> <div id="footmain"> <div id="footmainr"> <image src="images/copyright.png"> </div> </div> </div> </body> </html> __HTML_END; ?> And this is the page where i add new categories... Code: [Select] <?php include("config.inc.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Roy Neale - Gallery</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="head"> <div id="headmain"> <div id="headleft"> <image src="images/bannertop.jpg"> </div> <div id="headright"> <div class="navimage"><a href="gallery.php"><img border="0" image src="images/gallery3.png" onmouseover="this.src='images/gallery2.png'" onmouseout="this.src='images/gallery3.png'"></image></a><!--start navimage--> </div><!--end navimage--> <div class="navimage"><image src="images/about.png" onmouseover="this.src='images/about2.png'" onmouseout="this.src='images/about.png'"></image><!--start navimage--> </div><!--end navimage--> <div class="navimage"><image src="images/contact.png" onmouseover="this.src='images/contact2.png'" onmouseout="this.src='images/contact.png'"></image><!--start navimage--> </div><!--end navimage--> </div> </div> </div> <div id="mid"> <div id="midleft"> </div> <div id="midright"> <div id="midrighttop3"> </div> <div id="midrightbottom2"> <?php if (isset($_POST['submit'])): $category_name = $_POST['category_name']; mysql_query( "INSERT INTO gallery_category(`category_name`) VALUES('".addslashes( $category_name )."' )" ); if (@mysql_query($sql)) { echo('<p>New category added</p>'); } else { echo('<p>New category added</p>'); } ?> <p><a href="<?=$_SERVER['PHP_SELF']?>">Add another category</a></p> <?php else: // Allow the user to enter a new category ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <p><br /> New Category: <input type="text" name="category_name" size="20" maxlength="255" /><br /> <input type="submit" name="submit" value="SUBMIT" /></p> </form> <?php endif; ?> <p><a href="preupload2.php">Back to Upload</a></p> </div> </div> </div> <div id="foot"> <div id="footmain"> <div id="footmainr"> <image src="images/copyright.png"> </div> </div> </div> </body> </html> I assume i just need to edit a few mysql queries add another upload form and a few new fields or tables to my database, but i dont know how yet. |