Jump to content

kicken

Gurus
  • Posts

    4,704
  • Joined

  • Last visited

  • Days Won

    179

Everything posted by kicken

  1. Without knowing what $conn->execute does, we can't say much about how your code is going to process. Based on your description it sounds as though it will return a true-ish value regardless of if actual rows are found or not. If that is the case you will need to find another way of determining whether a row was actually found. If you provide details on what $conn->execute does, by providing it's source for example, perhaps we can further help you figure out how to properly detect an empty result set. Also, for future reference, you need to enclose your code within tags when you post it. Failure to do so will greatly decrease your chances of getting help.
  2. Delete that line, and maybe the line before it, and re-type it. Do not just copy/paste. You may have a hidden/invalid character in there which is not being displayed in your editor, or here on the forums.
  3. All you need to do is call srand with a value before your array_rand call. That will seed the generator PHP uses and cause array_rand to return predictable results. <?php $range = range('a','z'); if (isset($_GET['seed'])) srand($_GET['seed']); var_dump(array_rand($range, 5));
  4. All you have to do is change your INSERT to: $sql="INSERT INTO Models(MANU_ID, MOD_Name) VALUES ($ManuId, '$_POST[model]')"; The question is then where do you get the value for $ManuId from? If in your code you've just done an INSERT into the Manufacturers table then you can use the last insert id function (check the manual for whatever api you are using) to retrieve the newly generated MANU_ID from the Manufacturers table. If you're trying to add a model for some already existing entry then you'd have to pass the MANU_ID via the $_GET or $_POST data.
  5. You're error message shows the problem in header.php, but yet you don't show the relevant portion of that file. Based on what you have shown however, I am going to assume you are trying to use that variable from within the DisplayHeader function. If that is the case, you need to read up on variable scope.
  6. First off, you posted this in the wrong section. You posted in the Microsoft SQL Server forums, which is an entirely different product from Mysql which is what you are actually using. I've moved your post for you. Secondly, review this bit of the manual: 6.1.6. Security Issues with LOAD DATA LOCAL. That will provide you with info about how to determine why it is disabled. It may be that there is nothing easy you can to do enable it. In that case you'd have to develop your own import utility which will parse the file and generate insert statements.
  7. If you initiate a download on a server, it would use that server's internet connection, not your personal internet connection. Unless your server happens to use the same personal connection (ie, a server at your house) that is.
  8. I've not taken it, but looking at the topics I would imagine if you have 5 years of experience and are reasonably versed in the various topics then you should be able to pass it fine. Probably the most important bit to be comfortable with would be how to use the various types of JOINs to achieve desired results, not only with select statements but update/delete as well. Also knowledge of various syntax such as INSERT INTO blah SET ..., INSERT INTO ... SELECT, etc. The import/export sections probably deal with things like LOAD DATA and selecting to an OUTFILE, as well as possibly mysqldump. Take a moment to make sure you review those. The tables section of the data definition portion might dabble into things like PARTITIONING and different storage engines and their capabilities, a quick review of those may be useful. Overall though based on the info available, after 5 years of experience, and a day skimming/reviewing the manual you should be capable of passing the test without much issue. I'd feel comfortable taking it in such a situation.
  9. In addition, you almost certainly do not want the / at the beginning of the path in $the_file. That would indicate from the root of the filesystem which generally is not correct.
  10. Have both the image and the social box float: left; See: http://cssdesk.com/ywJGT
  11. Just use your $row_count variable as part of the ID. id='vendor_{$row_count}'Change the label's for attribute to match whatever ID you use.
  12. Every checkbox needs to have it's own ID. Right now they are all set to id="squaredTwo" which is invalid as an ID must be unique throughout the entire HTML document. The browser will keep the first instance of that ID, and ignore every other one.
  13. The rules for how files are located when using include/require are a bit complicated. Basically, it goes though a process something like: - If an absolute path is given, check only that path - If a relative path beginning with ./ or ../ is given, check against the current working directory. - If no path, or a relative path without ./ or ../ is given, check against the include_path entries, then against the working directory, lastly against the calling scripts directory. If the file is not found after all those checks it fails. Note that when it says the calling scripts directory this means the directory of the initial script which was executed, NOT the script containing the include/require directive. In your case, the initial script to be executed was (~ meaning document root) ~/html/portfolio/portfolio.php, that makes the calling scripts directory=~/html/portfolio/. Typically in a web environment, the current working directory is also set to this same value initially. So when you include the header file, php resolves it against the current working directory (~/html/portfolio/) which yields the path ~/inc/header.php. This file exist so PHP uses it. Next, when the header includes the main file, php again resolves that path against the current working directory (~/html/portfolio/) yields the path ~/html/lang/main.php. This file does not exist, so the include fails. Given these rules, you can see that it is typically best to give an absolute path to your include and require directives. One way to do this is as shown above, define a constant value which you then prefix to your paths. Another way is to add a path to the include_path and let PHP resolve names that way. For example if you had: //Where ~ represents your root directory set_include_path(get_include_path().PATH_SEPARATOR.'~'); require_once 'inc/header.php'; then in header.php require_once 'lang/main.php'; things would work out. What I typically do is have a single file somewhere which is always included. That file will define a constant to the root of the site and then add that to the include path. For example, I typically make this file ~/includes/common.inc.php, and it would contain: define('DOCUMENT_ROOT', dirname(__DIR__)); set_include_path(get_include_path().PATH_SEPARATOR.DOCUMENT_ROOT); Each of my scripts will contain a line to include the common.inc.php file (using ../ if necessary, ie require '../../includes/common.inc.php') at the top, all further includes will be relative to that root (ie require 'tcpdf/tcpdf.php')
  14. Change $merchData = array($EventFees_item2=>$EventFees_item_qty); to $merchData[$EventFees_item2] = $EventFees_item_qty;
  15. There's not much we can tell you without seeing the PHP code and the contents of the database. You seem to have multiple entries in your database matching the given code. Yes, maybe someone injected them somehow. Maybe you added them at some point and just forgot.
  16. Back in the day (IE 5/NS4/etc) what happened when you submitted a form with the enter key varied from browser to browser. I forget what each browser did exactly. At this point, last I checked anyway, it seems that the browsers have all pretty much standardized on sending the first button name/value pair. The HTML5 spec seems to dictate this as the standard behavior:
  17. Yes, the value passed would be what you put into the value="" attribute, which is also what is displayed. In addition, you do not need several forms. Since your Display/Update/Delete go to the same page, they can all be in one form. <form name='1' action='Page3.php' method='post'> <input type='Submit' name="function" value='Insert'> </form> <form name='1' action='Page2.php' method='post'> <input type='Submit' name="function" value='Display'> <input type='Submit' name="function" value='Update'> <input type='Submit' name="function" value='Delete'> </form> On page2.php, $_POST['function'] will be set to either Display, Update, or Delete depending on the button clicked.
  18. You have an ID column in both tables, so you need to be explicit about which table's ID column you are referring to. In your WHERE clause, you have the condition: shouts.id = id The second id column reference has no table prefix so mysql does not know which id column it should use.
  19. Do you have your perl script generating proper headers as part of it's output? It's been a long time since I did anything with perl, and never with IIS but from what I remember it was necessary. Eg: #!/bin/perl print "Content-type: text/html\r\n\r\n"; print '<html><head><title>Blah</title></head><body>Hi!</body></html>';
  20. Read up on arrays
  21. For an app I've been working on, I chose to store them as rows in a separate table. At the moment all I do is restore them to display the polygon so a simple encoded field would have worked just as well, however I figure it would be best to keep things separate just incase the future of the app needs it. It does not require much additional overhead to re-combine the rows into an array of points. These are my table setups CREATE TABLE geofences ( FenceId INT NOT NULL AUTO_INCREMENT PRIMARY KEY , Name VARCHAR(100) NOT NULL ); CREATE TABLE geofence_points ( FenceId INT NOT NULL , PointNumber INT NOT NULL , Latitude DOUBLE NOT NULL , Longitude DOUBLE NOT NULL , PRIMARY KEY (FenceId, PointNumber) ); To display the fence, combine all the points into an array when pulling them from the DB. The code looks a bit like this: $sql = ' SELECT gf.FenceId as fenceId, gf.Name as fenceName, gfp.PointNumber as pointNumber, gfp.Latitude as latitude, gfp.Longitude as longitude FROM geofences gf INNER JOIN geofence_points gfp ON gf.FenceId=gfp.FenceId WHERE gf.FenceId=:id ORDER BY gfp.PointNumber '; $stmt = $db->prepare($sql); if (!$stmt) die('<pre>'.print_r($db->errorInfo(),true).'</pre>'); $stmt->bindValue(':id', $EditId); if (!$stmt->execute()) die('<pre>'.print_r($stmt->errorInfo(),true).'</pre>'); while ($row=$stmt->fetch()){ if (empty($FenceData)){ $FenceData=array( 'fenceId' => $row['fenceId'] , 'fenceName' => $row['fenceName'] , 'path' => array() ); } $FenceData['path'][$row['pointNumber']] = array('lat' => floatval($row['latitude']), 'lng' => floatval($row['longitude'])); }
  22. On the jquery side of things, you need to capture the click of the next/previous links and make an ajax request. On the PHP side of things you'd want a bit of code to respond to that ajax request. You can either have PHP output new HTML and have jQuery replace the existing HTML or you could output a small json object w/ necessary details and update the HTML. For example, given the starting HTML of something like: <div id="singleImage"> <img src="image2.jpg" id="image"> <a href="gallery.php?image=1" id="prev">Prev</a> <a href="gallery.php?image=3" id="next">Next</a> </div> You'd write some jQuery such as: $(function(){ $('#prev, #next').click(function(e){ //Prevent the browser from folloing the link. e.preventDefault(); //Request the data via ajax. this refers to the <a> tag, this.href is it's href attribute value $.get(this.href, function(o){ //Change the attributes of the image, prev, and next elements. $('#prev').attr('href', o.prevHref); $('#next').attr('href', o.nextHref); $('#image').attr('src', o.imageSource); }, 'json'); //The 'json' indicates we want the return data to be treated as json }); }); That will register an onclick handler to both the next and previous links. When that handler is triggered it will cancel the browser's default action of following the links and instead make an AJAX request to your script requesting the next or previous image. It expects a JSON response containing an object with three properties:.prevHref - The new URL for the previous link .nextHref - The new URL for the next link .imageSource - The new URL for the image source The next step is to have your PHP script detect that it is an AJAX request and respond accordingly. Whenever jQuery sends an AJAX request, it includes a custom header called X-Requested-With set to the value XMLHttpRequest. You can test for this in your PHP script. For example: <?php if(isset($_GET['image'])){ $image = $_GET['image']; $image_arr = $image_class->fetchImage($image); if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest'){ //This is an AJAX request so respond with json header('Content-type: text/json'); echo json_encode(array( 'nextHref' => 'gallery.php?image='.$image_arr['nextId'] , 'prevHref' => 'gallery.php?image='.$image_arr['previousId'] , 'imageSource' => $image_arr['source'] )); exit; } else { //This is a normal request, respond with the full HTML require('pages/display_single_image.html'); //uses $image_arr to get the image path etc. } } Of course, I am making broad assumptions there regarding your data and HTML structure. You'll need to modify to match your real setup. This should be enough to let you see the concept and get you started at least however.
  23. If you want to find out more about why it is only using the last item the way it is now, read through Closures on MDN, in particular the bit titled Creating closures in loops: A common mistake. In there they recommend creating a factory function to solve the issue. This would work, however in your case it is not necessary. You may use this inside your callback function to refer to the polygon that was clicked. google.maps.event.addListener(dbpolygon, 'click', function() { setSelection(this); });
  24. Your first three queries could be turned into this: SELECT Sesson_date , SUM(CASE WHEN After_hour='Yes' THEN 1 ELSE 0 END) as numAfterHours , SUM(CASE WHEN Appointment != 'No' THEN 1 ELSE 0 END) as numAppointments , SUM(1) as numSalesCalls FROM Calls WHERE Dealership=$_SESSION['dealership'] AND Session_date BETWEEN $current_date AND ($current_date+INTERVAL $total_days) GROUP BY Session_date You'll need to make sure you handle all the variables properly, I just stuck them there so you can see where they belong. What that will do is return several rows, one for each day. Each row will contain columns for each of your counts. The last query, since it uses a different table and fields will need to be separate, however you can do similar to the above to return all the data in one go rather than a separate query for each day: SELECT Stat_date , COUNT(*) as numDealerCalls FROM Stats WHERE Stat_type='Total_Dealer_Calls' AND Stat_name=$_SESSION['dealership'] AND Stat_date BETWEEN $current_date AND ($current_date+INTERVAL $total_days) GROUP BY Stat_date The one potential issue here is if there are no matching rows for a particular day, that day will not be included in the output. So if you ran this today and there was no future data, then only one row for 8/20/2013 would be returned. 8/21/2013-8/30/2013 would not show in the result set. If you want to make sure that all 10 days appear on your page you'll need to generate a list of the days still and merge the results with that list. A simple way to do this would be to generate the days and store them in an array as keys, then assign the query results as values to those entries. For example: This would generate the array of days $start = new DateTime('2013-8-20'); $allDays = array(); for ($i=0; $i<10; $i++){ $allDays[$start->format('Y-m-d')] = array(); $start->modify('+1 day'); } Then when you loop the results: while ($row=$result->fetch()){ $allDays[$row['date']]['numAfterHours'] = $row['numAfterHours']; //... } $row['date'] would have to match the same format you use for they key in the array. You can use mysql's DATE_FORMAT function to create a matching format.
  25. Use a foreach loop over the return value from sqlsrv_fetch_array. while($row = sqlsrv_fetch_array($stmt)) { foreach ($row as $column=>$value){ echo $column.": ".$value."<br>"; } echo '<hr>'; }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.