PHP - Displaying Ms Access Query In Php Page
I have an MS Access Database that resides on the server that I will be hosting the pages I'm building.
In my MS Access Database I have a query called "CheckedInEquipment" that I would like to have constantly display on a PHP page. It needs to be 'fluid', so the data is always up to date on the web page. (This is all in a sandbox XAMPP environment). Has anyone done this, can you lead me to examples or push me in the right direction? Carl Similar TutorialsWhat is the best way to display the next record on a web page, from a list of records, without executing the query over and over again each time you display the next record? For example, imagine my user has a list of messages displayed on a web page, and the user filters that list to display all messages with the title "Test", and let's say that returns 12 records. He then clicks on record 1 to read that message. Once he is done reading it, he then wants to read msg 2, and then msg 3 etc. He could hit the Back button in his browser and click on the next record from the list, but it would be more useful to just click on a link that says "Next" which displays the next message in the filtered list of messages (without having to go back to the list). A lot of web sites do this sort of thing, but what is the best way to do it? Do you have to run the original query again each time a new message is loaded, so you know which message is next, or can you somehow store the query to save the server from having to run the same query over and over again? If a user is viewing a list of pictures for example, they could be flicking through the pictures quite quickly, and I would not like to have the server running the same query over and over again every few seconds when it doesn't need to. Advice? (Thanks.) I have a search form. $req is a keyword or an ID number input by user. As you can see, query checks only for rows where userID matches the current login userID. My question is, how to transform (not independent query for admins) the query to search all rows if user $access is admin (no matter the administrator's own userID). Code: [Select] <?php $userID="something"; (from session) $access="something" (from session / user or admin) $query="SELECT esName, esID, esAddress FROM estates WHERE (esName LIKE '$req' OR esID LIKE '$req') AND userID='$userID'"; mysql_query($query); ?> Thanks in advance i have created an object in one page. it has a submit button which upon clicking opens a new page. is it possible to access that created object and its data members in that second page? here is the code for creating the object in the first page. $viewcart = new Cart(); $viewcart->GetProductCart($user); Hi, my site is displaying something weird, http://86.21.243.231/ on the table at the bottom, it should list the amount of tickets sold. if the user deposits 0.3, then it should display 3 seperate rows for 0.1 with their payout address. but for 0.3, it displays 2 rows of 0.15 instead. the code for the table is: Code: [Select] $sql="SELECT * FROM tickets WHERE `round` = '$round' AND `confirmed` = 'yes' ORDER BY timestamp ASC"; $result=mysql_query($sql); $row=mysql_fetch_array($result); $result=mysql_query($sql); while($row = mysql_fetch_array( $result )) { $ticketamount = $row['amount']; $ticketspurchased = (int)($ticketamount / $ticketprice); $ticketamount = $ticketamount / $ticketspurchased; for ( $counter = 1; $counter <= $ticketspurchased; $counter += 1) { $i++; echo "<tr><td>"; echo $i; echo "</td><td>"; echo $row['address']; echo "</td><td>"; echo $ticketamount; echo "</td><td>"; echo $row['confirmed']; echo "</td><td>"; echo $row['timestamp']; echo "</td></tr>"; } } 0.5 shows correctly Any ideas? Hi everyone. I'm stuck on the following query. I need to display all the fields listed below on a page, but linked via communications.CommID. I'd appreciate any assistance you can provide. thank you. Code: [Select] <?php $result = mysql_query("SELECT records.NameFirst_1, records.NameLast_1, records.CompanyName, records.CompanyBranch, records.CompanyReferenceNumber, records.CaseOwnerSelect, communications.ConversionType, communications.Contact, communications.ContactFrom, communications.CommID, communications.ContactPosition, communications.ContactTelephone, communications.ContactEmail, communications.ContactFax, communications.CallDate, communications.CallTime, communications.ActionTextField FROM records INNER JOIN communications ON records.IDNumber = '$IDNumber'") or die(mysql_error()); $row = mysql_fetch_array($result); ?> Hello! I am busy developing a script that returns all users that have the cell "Available" set to 1 but I am unsure how to do this, I am familiar with basic SQL and I have made this: $sql = "SELECT * FROM `clans` WHERE `available` =1 LIMIT 0 , 30"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo ($row['name']); but it only displays information from the first row found, and I want it to display all the rows found, how can I do this? Thanks - GreenFanta This has been an ongoing issue from the start. When I try to login I enter the username and password and click login, then get taken back to the login page to reenter the same details and the second time I click login I get logged in. Now if I then log out and close window and wait a few seconds, restart again and try to log in, I get in first time. I believe this could be a session issue but I thought unsetting the unset($_SESSION['admin']); would cause the session to be lost and have to start again. I just can not get my head around what is causing it. Can anyone tell me what I might be doing wrong ? I have a redirect to originating page, so if I was to view a previous page within the admin area I have to log in and then once loggeed in it will redirect to the page I was on before. Here are my scripts.
<?php session_set_cookie_params(0, '/', '.****.com'); session_start(); error_reporting(-1); define('site_title', 'Admin '); define('pageTitle', 'Admin '); $_SESSION['loginRedirect'] = "adminCreateCampaign.php"; include("functions-for-email.php"); $checkAdminStatus = checkAdminStatus($mysqli); if(!isset($_SESSION['admin']) || $checkAdminStatus == "NOACCESS") { $_SESSION['error'] = 'You must be logged in to view that page. (el.S1)'; //$_SESSION['loginRedirect'] = "showStats.php"; //echo("You must be logged in to view that page. (el.S1)<br>"); exit; @mysqli_close($mysqli); header('Location: ' . adminFullWebAddress . '/index.php'); exit; } else { if($_SESSION['admin']['account_type'] != 'admin') { $_SESSION['error'] = 'You do not have the priviledges to view that page. (el.S2)'; @mysqli_close($mysqli); header('Location: ' . adminFullWebAddress . '/index.php'); exit; } } ?> <!DOCTYPE> <html> <head> <link href="adminstyle.css" rel="stylesheet" type="text/css" /> <title><?php echo(site_title); ?></title> </head> <body> <div id="container"> <div class="containerInner"> <div id="leftInner100"> <?php // start of leftInner ?> <?php menu(); ?> <h1 class="middleTitle">Admin </h1> <?php if(isset($thisError)) { echo '<div class="errorDiv">',$thisError,'</div>'; unset($thisError); } if(isset($thisSuccess)) { echo '<div class="successDiv">',$thisSuccess,'</div>'; unset($thisSuccess); } ?> <br><br> </div><?php // end of leftInner ?> </div><?php // end of containerInner ?> <div class="clearfix"></div> </div><?php // container ?> </body> </html> <?php @mysqli_close($mysqli); ?>
<?php session_set_cookie_params(0, '/', '.****.com'); session_start(); error_reporting(-1); include("functions.php"); $checkAdminStatus = checkAdminStatus($mysqli); //$_SESSION['loginRedirect'] = adminFullWebAddress . "/index.php"; $fromlink4 = isset($_SERVER['REMOTE_ADDR']) ? (gethostbyaddr($_SERVER['REMOTE_ADDR'])) : "empty"; $ipAddress = $_SERVER['REMOTE_ADDR']; if(isset($_POST['email'])) { $email = $_POST['email']; $email = strip_tags($email); } else { $email = ""; } if(isset($_POST['pass'])) { $password = $_POST['pass']; $pass = $_POST['pass']; } else { $pass = ""; } if(isset($_POST['login']) && trim($_POST['login']) == 'Login') { $checkEmail = db_query($mysqli, "SELECT `adminid` FROM `admins` WHERE `email` = '" . $mysqli->real_escape_string($email) . "' LIMIT 1"); $checkBanned = db_query($mysqli, "SELECT `adminid` FROM `admins` WHERE `email` = '" . $mysqli->real_escape_string($email) . "' AND `suspended` = 'Yes' LIMIT 1"); $failedLoginCounter = 0; if(!$email) { $thisError = 'Please enter your e-mail address.'; } else if(! $checkEmail->num_rows) { $thisError = 'Either the email address, password or both were not entered correctly.'; } else if(!$password) { $thisError = 'Please enter your password.'; } else if($checkBanned->num_rows) { $thisError = 'Your account has been suspended by Admin.'; } else { $password = md5($password); $checkAccount = db_query($mysqli, "SELECT * FROM `admins` WHERE `email` = '" . $mysqli->real_escape_string($email) . "' AND `password` = '" . $mysqli->real_escape_string($password) . "' LIMIT 1"); if($checkAccount->num_rows) { $saveChanges = db_query($mysqli, "UPDATE `admins` SET `lastlogindatetime` = '" . $mysqli->real_escape_string(datetimenow) . "', `lastAccessSinceLogin` = '" . $mysqli->real_escape_string(datetimenow) . "', `lastloginip` = '" . $mysqli->real_escape_string($ipAddress) . "', `failedLoginCounter` = 0 WHERE `email` = '" . $mysqli->real_escape_string($email) . "' LIMIT 1"); // set lastlogindatetime $_SESSION['admin'] = $checkAccount->fetch_assoc(); $loginRedirect = isset($_SESSION['loginRedirect']) ? $_SESSION['loginRedirect'] : ""; $_SESSION['success'] = 'You are now logged in. (ok.L2) ' . $loginRedirect; header('Location: ' . adminFullWebAddress . '/' . $loginRedirect); exit; } else { $thisError = 'Your e-mail address and/or password is incorrect.<br>If you still face issues, you can <a href="startresetpw.php">reset your password</a>'; $saveChanges = db_query($mysqli, "UPDATE `admins` SET `failedLoginCounter` = `failedLoginCounter` + 1, `lastloginfailedip` = '" . $mysqli->real_escape_string($ipAddress) . "', `lastlogindatetimeFailed` = '" . $mysqli->real_escape_string(datetimenow) . "' WHERE `email` = '" . $mysqli->real_escape_string($email) . "' LIMIT 1"); // set lastlogindatetimeFailed } } } if(!isset($_SESSION['admin'])) { define('site_title', 'Login'); define('pageTitle', 'Login'); } else { define('site_title', 'Home'); define('pageTitle', 'Home'); } ?> <!DOCTYPE> <html> <head> <link href="adminstyle.css" rel="stylesheet" type="text/css" /> <title><?php echo(site_title); ?></title> </head> <body> <div id="container"> <div class="containerInner"> <div id="leftInner100"> <?php // start of leftInner ?> <div id="mainphoto"><?php //specialMessage($mysqli); mainPageImage(""); ?></div> <div class="clear"></div><?php if(isset($_SESSION['admin'])) { menu(); } if(isset($thisError)) { echo '<div class="errorDiv">',$thisError,'</div>'; } if(isset($thisSuccess)) { echo '<div class="successDiv">',$thisSuccess,'</div>'; } unset($thisError); unset($thisSuccess); if(!isset($_SESSION['admin'])) { ?> <div style="width: 100%; margin: 0em auto; text-align: center;"> <form method="POST" action="index.php" style="width: 15em; text-align: center;"> <div class="field"> E-mail Address </div> <div class="value"> <input type="text" name="email" value="<?php if(isset($_POST['email'])) { echo $email; } ?>" style="width: 12.5em;" title="email"> </div> <div class="field"> Password<br><span style="font-size: 0.8em;"><?php if (isset($_POST['pass'])) { echo('<strong style="color: red;">'); } ?>(Please note: your password may be CaSe SeNSitIvE)<?php if (isset($_POST['pass'])) { echo('</strong>'); } ?></span> </div> <div class="value"> <input type="password" name="pass" value="" style="width: 12.5em;" title="pass"> </div> <div><br><input type="submit" name="login" value="Login"> <input type="reset" value="Clear"><br></div> </form><br> <div class="clearFloat"></div> </div> <?php } else { ?>logged in<?php } ?> <br><br> </div><?php // end of leftInner ?> </div><?php // end of containerInner ?> <div class="clearfix"></div> </div><?php // container ?> </body> </html> <?php @mysqli_close($mysqli); ?> functions.php <?php define('showOutput', 0); include("/home/****/db_login_functions.php"); define('db_table_name', 'clientList'); define('mailHost', 'mail.****.com'); define('mailUsername', 'noreply@****.com'); define('mailPW', '****'); define('bounce', 'bounce@****.com'); define('fullDomain', 'https://www.admin.****.com'); define('adminFullWebAddress', 'https://www.admin.****.com'); define('adminEmail', 'admin@****.com'); define('fromEmail', 'noreply@****.com'); define('fromName', 'DO NOT REPLY'); define('REMOTEADDR', isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''); define('PHPSELF', $_SERVER['PHP_SELF']); define('HTTPREFERER', isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "not set"); define('unsub', 'https://www.****.com/unsub.php'); define('securityhash', 'abc'); // NEVER change this securityhash. date_default_timezone_set('Europe/London'); define('datetimenow', date("Y-m-d H:i:s")); /* check if user is allowed to access a certain page or not. */ function checkAdminStatus($mysqli) { $yesNo = ""; if(isset($_GET['action']) && $_GET['action'] == 'logout') { unset($_SESSION['admin']); $_SESSION['success'] = 'You have successfully logged out. (lo.1)'; header('Location: index.php'); exit; } if(isset($_SESSION['admin']) ) { // need to add in code to check if logged in for more than 1 hour, if so log out on next refresh of page. if ($_SESSION['admin']['lastAccessSinceLogin'] < date( 'Y-m-d H:i:s', strtotime("-5 minutes") )) { unset($_SESSION['admin']); $_SESSION['error'] = 'You were logged out due to no activity, please login again to view that page. (lo.2)'; header('Location: index.php'); exit; } $checkBanned = db_query($mysqli, "SELECT `adminid` FROM `admins` WHERE `email` = '" . $mysqli->real_escape_string($_SESSION['admin']['email']) . "' AND `suspended` = 'Yes' LIMIT 1"); if($checkBanned->num_rows) { $yesNo = "NOACCESS"; //$_SESSION['error'] = 'You must be logged in to view that page.'; } else { $yesNo = "ACCESS"; // if logged in, update `users`.`lastAccessSinceLogin` with current datetime. $updateLastAccessSinceLogin = db_query($mysqli, "UPDATE `admins` SET `lastAccessSinceLogin` = '" . $mysqli->real_escape_string(datetimenow) . "', `lastloginip` = '" . $mysqli->real_escape_string(REMOTEADDR) . "', `failedLoginCounter` = 0 WHERE `email` = '" . $mysqli->real_escape_string($_SESSION['admin']['email']) . "' LIMIT 1"); $_SESSION['admin']['lastAccessSinceLogin'] = datetimenow; } } return $yesNo; } function menu() { echo('<a href="index.php?action=logout">Log Out</a> '); echo(' <a href="adminCreateCampaign.php">Create Campaign</a><br><br><br>'); } ?>
.htaccess (within the admin folder) Header set Access-Control-Allow-Origin "*" RewriteEngine On RewriteCond %{HTTPS} off # First rewrite to HTTPS: # Don't put www. here. If it is already there it will be included, if not # the subsequent rule will catch it. RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # Now, rewrite any request to the wrong domain to use www. # [NC] is a case-insensitive match RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] ### DON'T DELETE!! Below entry is MUST for your PHP sites like wordpress,joomla and etc to work properly. suPHP_ConfigPath /home/****/php.ini .htaccess (within the root folder) Header set Access-Control-Allow-Origin "*" RewriteEngine On RewriteCond %{HTTPS} off # First rewrite to HTTPS: # Don't put www. here. If it is already there it will be included, if not # the subsequent rule will catch it. RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # Now, rewrite any request to the wrong domain to use www. # [NC] is a case-insensitive match RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] ### DON'T DELETE!! Below entry is MUST for your PHP sites like wordpress,joomla and etc to work properly. suPHP_ConfigPath /home/****/php.ini the php.ini file allow_url_fopen = on allow_irl_include = on date.timezone = Europe/London safe_mode = off upload_max_filesize = 20M post_max_size = 20M upload_tmp_dir = "/home/****/tmp" session.save_path = "/home/****/sessions" session.use_only_cookies = on error_reporting = E_ALL log_errors = On display_errors = Off track_errors = On error_log = "/home/****/errors.log" sendmail_from = "server@****.com"
I want to make it so public users cant access the index of/ page, how do I do that? Thanks Hello - Suppose I had a MySQL result set that was something like this: ITEM: COLOR: ball red ball blue book red book green book black If I were to use the code: Code: [Select] do { echo $row_myQuery['item'] . " - " . echo $row_myQuery['color'] . "<br />"; } while ($row_myQuery= mysql_fetch_assoc($myQuery)); Then I end up with this: Code: [Select] ball - red ball - blue book - red book - green book - black MY QUESTION: What I'd like to know is, how could I re-write that php code so that I could get an output like this?: Code: [Select] ball - red, blue book - red, green, black Thanks! Ok so I am pretty good with mysql and performing queries to get the data that I need. However, I have a question for any of you gurus out there that may be able to help me with an issue that I always run into with certain types of queries. Say I have 2 tables like this: Galleries id name 1 My Photos Gallery Photos id gallery_id photo 1 1 photo1.jpg 2 1 photo2.jpg 3 1 photo3.jpg Now usually when I pull this info from the database I have to do 2 separate queries in order to get the data and then link them so I would do something like. <?php //make the gallery query $query = "SELECT * FROM galleries"; $results = mysql_query($query); //setup an array for the galleries data $gallery_data = array(); //loop through the galleries for($i=0;$i<mysql_num_rows($results);$i++){ //add the gallery info to the gallery data array $gallery_data[$i] = mysql_fetch_array($results); //make the photos query with the gallery id $photo_query = "SELECT * FROM gallery_photos WHERE gallery_id='".mysql_real_escape_string($gallery_data[$i]['id'])."'"; $photo_results = mysql_query($photo_query); //setup the photos array $photo_data = array(); //put the photos in the array for($n=0;$n<mysql_num_rows($photo_results);$n++){ $photo_data[$n] = mysql_fetch_array($photo_results); } //add the photos to the gallery array $gallery_data[$i]['photos'] = $photo_data; } //now to display it is like this if(is_array($gallery_data)){ foreach($gallery_data as $gallery){ echo $gallery['name']; //show the photos if(is_array($gallery['photos'])){ foreach($gallery['photos'] as $photo){ echo $photo['photo']; } } } } ?> So my question is there a way to get all of this data at one time. I know how to do multiple queries in one and to do joins but they can only return one row as far as I know of. The only other way that I know how to do this is by ordering them by name and selecting them directly from the photos table and then just getting the gallery name like this: SELECT *,(SELECT name FROM galleries WHERE id=gallery_photos.id) AS gallery_name FROM gallery_photos ORDER BY gallery_id Then I could just do one loop and see if the name has changed and if so to output the new name. But I would like to know if there is a way to get a second set of results as an array from a query so I could just select the galleries and photos all in one query. Any help is appreciated. Hey all, First off, if this is in the wrong section I apologize. I wasn't sure if it should be here or the mySQL section. What's going on is, I'm in the process of learning the Prepared Statement way of doing things and am changing / updating my code to reflect the changes. Everything was going fine until I attempted to do what I could do using old MySQL methods and that is display the queried results on the same page. I can place a query and display the results as they should be displayed if I only use one block of code. However, if I try to do any additional queries on the same page, they get killed and do not display anything even though I know the query is fine because I can test the exact same syntax below one a different page and it works. Here's a code snippet for an example: Code: [Select] Code: <table> <tr> <td> // The below code will display a selection box containing various strings such as "hello world", "great to be here", "Wowserz", "this is mind blowing" etc. that are stored in the database. <?php echo "<select = \"SpecialConditions\">"; if($stmt->num_rows == NULL){ echo "No results found."; }else{ while($stmt->fetch()){ echo "<option value=\"$specialId\">$specialcondition</option>"; } } echo "</select>"; ?> </td> <td> // If I place another fetch query below the above fetch() query, this one will not show up. This one is supposed to display values 1 - 20 that have been stored in the DB. <?php echo "<select = \"NumberSets\">"; if($stmt->num_rows == NULL){ echo "No results found."; }else{ while($stmt->fetch()){ echo "<option value=\"".$numbers."\">".$numbers."</option>"; } } echo "</select>"; ?> </td> </tr> </table> What am I doing wrong with this? When I use regular SQL queries I can display multiple results on the same page. The results are being pulled from two separate joined tables but I don't think that's the issue. Hello all, I'm relatively new to all of this, but making progress.... I figure this has come up before, but couldn't fin anything by search or browsing. I have an sql table that is cron updated every two minutes from externally generated data in table X columns a,b,c,... . As part of more complicated site, I have one body element page (selected by a tab in the header) that does various sql queries on the data in table X and displays the data. I need this to rerun the queries and update the displayed results every 2 minutes or so as well. However, the standard solutions do not seem to be working: <META HTTP-EQUIV="refresh" CONTENT="15"> A refresh button refreshes the entire site, and not just this element. <FORM> <INPUT TYPE="button" onClick="history.go(0)" VALUE="Force Flight Data Refresh"> </FORM> I hope it is clear. Any ideas of how I could get this to work? Thanks, Kalle Here is a snippet of the code on that page for what it's worth... </head> <body> <div id="header"> <center><h2><font color="red">TRAFFIC INFORMATION</font></h2> </div> <div id="navigation"> </div> <div id="content"> <!-- refresh button --> <FORM> <INPUT TYPE="button" onClick="history.go(0)" VALUE="Force Flight Data Refresh"> </FORM> </center> <?php $IDS->db_build($db); $IDS->db_query($db,$res,"SELECT * FROM `Pilots` WHERE `dest`='KORD'"); echo "<h5>Arrivals to O'Ha </h5>"; while ($arr_row = mysql_fetch_assoc($res)) { echo "<font color=yellow>".$arr_row['callsign']."</font> using route: ". $arr_row['route']."<br>"; } //end queries //close connect to sql database mysql_close($con) </div> <div id="footer"> </div> </body> </html> Hi guys so i want to make page acces to certain ranks. So im thinking for something like this
rank1 -> home.php, admins.php So the ranks are in a database with the page names. So now when someone logs in they will get a certain rank. So now i need to make a function that will check if the rank has access to this page. $curPageName = substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1); This will detect the current page that the logged in person is at now. But now how do i check if the $_SESSION['rank']; (rank1) has the access to get in page admins.php, and obviously to make $_SESSION['rank'];(rank2) redirect from the page admins.php Could someone point me in the right direction? Do i select the ranks and page names from database then put it into a array? Thanks. Hello, Im making a little script to grab some data from a website but the data loads up a Javascript popup and unless you click the link from the page you came from you get a 404 error. Is there any ways to able me to load up the page using php so i can access some of the data on the page. The page im trying to access has the following code in the head, Does that have anything to do why you cant directly access it? Code: [Select] <META NAME="Robots" CONTENT="index,follow"> Hope this makes sense, If anyone knows a solution i would really appreciate it. I have a site, and there is an image with a link to another page, how can I make it so this is the only way to get to that page is by clicking on that image, and not by typing www.mywebsite.com/page.php into the address bar in a browser? Below is a page which is supposed to output the name, blog contribution and picture of contributing members of a website. <div id="blog_content" class="" style="height:90%; width:97%; border:5px solid #c0c0c0; background-color: #FFFFFF;"> <!--opens blog content--> <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //include the config file require_once("config.php"); //Define the query. Select all rows from firstname column in members table, title column in blogs table,and entry column in blogs table, sorting in ascneding order by the title entry, knowing that the id column in mebers table is the same as the id column in blogs table. $sql = "SELECT blogs.title,blogs.entry,members.firstname,images.image FROM blogs LEFT JOIN members ON blogs.member_id = members.member_id LEFT JOIN images ON blogs.member_id = images.member_id ORDER BY blogs.title ASC "; $query = mysql_query($sql); if($query !== false && mysql_num_rows($query) > 0) { while(($row = mysql_fetch_assoc($query)) !== false) { echo '<div id="blog_content1" style="float:left; position:relative;bottom:18px;left:13px; background-color: #FFFFFF; height:16.7%; width:100%; border:0px none none;" <!--opens blog_content1 same as main center top 1 and 2 from index page everything scaled down by a factor of 3, heightwise--> <div class="red_bar" style="height:3%; width:100%; border:1px solid #959595;"> <!--a--> <div class="shade1" style="height:5px; width:100%; border:0px none none;"> </div> <div class="shade2" style="height:5px; width:100%; border:0px none none"> </div> <div class="shade3" style="height:5px%; width:100%; border:0px none none"> </div> </div> <!-- closes red bar--> <div class="content" style="height:28.3%; width:100%; border:0px none none;"> <!----> <div class="slideshow" id="keylin" style="float:left; width:20%; border:0px none none;"> <!--a--> <div><img header("Content-type: image/jpeg"); name="" alt="" id="" height="105" width="105" src="$row[image]" /></div> </div> <!-- closes pic--> <div class="content_text" style="float:right; position:relative;top:7px;left:0px; max-height:150px; width:78.5%; border-width:4.5px; border-bottom-style:solid; border-right-style:solid; border-color:#c0c0c0; "> <!--a-->'; echo "<h3>".$row['title']."</h3>"; echo "<p>" .$row['entry']."<br />".$row['firstname']."</p>"; echo '</div> <!-- closes content text--> </div> <!-- closes content--> </div> <!-- closes blog_content1-->'; } } else if($query == false) { echo "<p>Query was not successful because:<strong>".mysql_error()."</strong></p>"; echo "<p>The query being run was \"".$sql."\"</p>"; } else if($query !== false && mysql_num_rows($query) == 0) { echo "<p>The query returned 0 results.</p>"; } mysql_close(); //Close the database connection. ?> </div> <!-- closes blog content--> The select query is designed to retrieve all the blog contributions(represented by the fields blogs.title and blogs.entry) from the database, alongside the contributing member (member.firstname) and the member's picture(images.image), using the member_id column to join the 3 tables involved, and outputs them on the webpage. The title, entry and firstname values are successfully displayed on the resulting page. However, I can't seem to figure out how to get the picture to be displayed. Note that the picture was successfully stored in the database and I was able to view it on a separate page using a simple select query. It is now just a question of how to get it to display on this particularly crowded page. Anyone knows how I can output the picture in the img tag? I tried placing the header("Content-type: image/jpeg"); statement at the top of the php segment, then just right below the select query and finally just right above the img tag, but in every case, I just got a big white blank page starring at me. How and where should I place the header statement? And what else am I to do to get this picture displayed? Any help is appreciated. On my web page, there is a variable called $submission. I would like to display exactly 11 rows from the query below: the row where $submission equals $row["title"], 5 rows above it, and 5 rows below it. All ranked by points descending. How can I do this? Code: [Select] $sqlStr = "SELECT title, points, submissionid FROM submission ORDER BY points DESC"; $result = mysql_query($sqlStr); $arr = array(); $count=1; echo "<table class=\"samplesrec\">"; while ($row = mysql_fetch_array($result)) { echo '<tr >'; echo '<td>'.$count++.'.</td>'; echo '<td class="sitename1">'.$row["title"].'</td>'; echo '<td class="sitename2"><div class="pointlink2">'.number_format($row["points"]).'</div></td>'; echo '</tr>'; } echo "</table>"; Below is the screenshots and script for user page level access i have used it for one of my old projects. Code is working as it was intended. But it needs to be improvised. Users table
pages table , which has all the pages and links
Access level table. which has user id from users table and page id from pages table (for which user has access)
Once the user is created, admin gives access to the user on page basis, the permissions.php page looks like this The modules
Menus inside the modules
Pages in each menu
Here is my code for permission.php <div id="demo2-html"> <ul id="demo2" class="mnav"> <li><a href="#">Sales</a> <ul> <li><a href="#">Lead</a> <ul> <table class="table table-bordered table-striped table-hover"> <?php $s1 = mysqli_query($con, "SELECT pages.page_id as pid, pages.code, pages.page, pages.href, access_level.aid, access_level.page_id as pgid, access_level.user_id FROM pages LEFT JOIN access_level ON (pages.page_id=access_level.page_id AND access_level.user_id=".$user." ) WHERE pages.code='led'") or die(mysqli_error($con)); while($s2 = mysqli_fetch_array($s1)) { ?> <tr><li><td><?php echo $s2['page']; ?> </td><td><input type="checkbox" name="sn[]" value="<?php echo $s2['pid']; ?>" <?php if($s2['pgid'] === $s2['pid']) echo 'checked="checked"';?> /> <input type="hidden" value="<?php echo $s2['pid']; ?>" name="page_id[<?php echo $s2['pgid']; ?>]"> </td></li></tr> <?php } ?> </table> </ul> </li> <li><a href="#">Customer</a> <ul> <table class="table table-bordered table-striped table-hover"> <?php $s1 = mysqli_query($con, "SELECT pages.page_id as pid, pages.code, pages.page, pages.href, access_level.aid, access_level.page_id as pgid, access_level.user_id FROM pages LEFT JOIN access_level ON (pages.page_id=access_level.page_id AND access_level.user_id=".$user." ) WHERE pages.code='cst'") or die(mysqli_error($con)); while($s2 = mysqli_fetch_array($s1)) { ?> <tr><li><td><?php echo $s2['page']; ?> </td><td><input type="checkbox" name="sn[]" value="<?php echo $s2['pid']; ?>" <?php if($s2['pgid'] === $s2['pid']) echo 'checked="checked"';?> /> <input type="hidden" value="<?php echo $s2['pid']; ?>" name="page_id[<?php echo $s2['pgid']; ?>]"> </td></li></tr> <?php } ?> </table> </ul> </li> //code goes for all the other modules </ul> </li> </ul> </div> <input type="hidden" name="user" value="<?php echo $user; ?>" /> <div class="row" align="center"> <input type="submit" name="submit" class="btn btn-success" value="Save" /> </form> // form Submission if(isset($_POST['submit'])) { $user = $_POST['user']; $sql = "DELETE FROM access_level WHERE user_id = ".$user.""; $query = mysqli_query($con, $sql) or die (mysqli_error($con)); foreach($_POST['sn'] as $sn) { $sql = "insert into access_level (page_id, user_id) values (".$sn.", ".$user.")"; $query = mysqli_query($con, $sql) or die (mysqli_error($con)); } if($query) { header("location:users.php?access=1"); } }
So against each user i am storing all the page ids here. When i edit any of the users, it deletes all the records and again insers new records. Which i feel is not a proper way to do. And in codewise also, i am redirecting the user to no_access.php (as below) page if the user do not have access. <?php ob_start(); include("connect.php"); include("admin_auth.php"); $q1 = basename($_SERVER['REQUEST_URI'], '?' . $_SERVER['QUERY_STRING']); $q2 = $_SERVER['REQUEST_URI']; $var1 = "/".$q1; $qa_path=explode('/', $q2); $right_path = $qa_path[2].$var1; $parsedUrl = parse_url($q2); $curdir = dirname($_SERVER['REQUEST_URI'])."/"; $m4 = "select p.page_id, p.code, p.page, p.href, al.aid, al.page_id, al.user_id FROM pages p INNER JOIN access_level al ON p.page_id=al.page_id WHERE al.user_id=".$_SESSION['user_id'].""; $m5 = mysqli_query($con, $m4) or die (mysqli_error($con)); while($nk1 = mysqli_fetch_array($m5)) { $href1[] = ($nk1['href']); } if(in_array($right_path, $href1)) { echo "<script type='text/javascript'> document.location = ".BASE_URL."/".$right_path."</script>"; } else { echo "<script type='text/javascript'> document.location = '../no_access.php' </script>"; exit(); } ?> I need help in improve and better/effective (structural) way to do this both in database and php script. |