-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
Just like you'd do any loop. function getParentList($currentId){ $list=array(); do { $sql = 'SELECT name, parent_id FROM kill4silence_photos_albums WHERE id='.intval($currentId); $res = mysql_query($sql); if ($res){ $row = mysql_fetch_assoc($res); $currentId = $row['parent_id']; $list[] = $row['name']; } else { $currentId = 0; } } while ($currentId != 0); return $list; } It's a valid approach. On the positive side, it's much simpler to implement and maintain. On the down side, it makes things like this bread crumb list less efficient. The better way is described in the link I posted above.
-
My guess is that your $products_image_base variable contains a '/' character, possibly as a directory separator. you'd have to print the variable to see what it contains. Since your using '/' as your regex delimiter, any instances of '/' inside your regex (in the variable) must be escaped by prefixing them with a '\' character. preg_quote should be able to take care of this for you.
-
Given your current db structure, you can do it one of two ways: 1) Issue a query to select the current albums name and parent id. Save the name and then repeat the query using the parent id just received as the new current album id. Continue this process until the parent id is 0 2) Choose most likely maximum nesting level (say, 6) and then issue a single query with a bunch of left joins. If you feel like changing the db structure, you could implement it as a nesting doll type approach, which makes things like querying the parent categories easy, but slightly complicates adding/removing items.
-
Will date comparison work by string comparison
kicken replied to sandeep529's topic in PHP Coding Help
Assuming all your dates are in YYYY-mm-dd format, they will compare correctly as strings. -
That query should be more like this: $idList = array_keys($_POST['close']); //Since your ID's are the keys in the array, not the values. $idList = array_map('intval', $idList); //Ensure all values are integers and not strings (protects from sql injection) $closequery = 'UPDATE sellerinfo SET Closed='y' WHERE Index IN ('.implode(',', $idList).')'; //Do not use mysql_real_escape_string in this instance. Since your row id is being used as an array key (name="close[xxx]"), you need to extract the keys of the close array. Using intval on all the keys will ensure they are integers and protect from any sql injection attempts. invalid values will be converted to 0, assuming you have no rows where index=0, they will essentially be ignored since they wont match any rows. Since we use intval to protect from sql injectection, mysql_real_escape_string is not needed. In any case, it's usage there is incorrect as you'd want to apply it to each value in the array, not the whole imploded string.
-
That's what you were told to do. At some point in your page you're running a query to fetch the information. If that query returns 0 rows, then (and only then) do you output those 404 headers. If the query does find data, you just continue on normally.
-
$query = 'ipmitool -I lanplus -H '.$devices.' -U admin -P adminpass sdr list'; Variables are not translated inside single-quote strings. You have to concatenate them, or change your string to use double-quotes.
-
Is it possible? Yes. It would be far easier and much more user-friendly to use javascript for this task though. To you PHP you would have to submit your form, and then re-create the entire form, just with an extra field, while also maintaining anything they had already typed in so they don't have to type it in again. With javascript, you can just use a couple DOM methods to create a new field and add it to the page, quick and simple. Then just make sure your PHP script is aware of these additional fields and processes them. Usually when I do something like these the dynamic fields are named as an array and I just use a foreach() loop on the php end.
-
If you have one variable and want to test against several possibilities, a switch is generally the way to go. I'm not sure what your concern is with "loose comparsion". Unless all your if statements are comparing using the === or !== operators then your performing a loose comparsion there as well and there's no difference between them and a switch, other than a switch being cleaner and easier to read. There's nothing wrong with a loose comparison generally. Only in a few instances might it cause a problem.
-
While Loop to list each Item and it's Comments
kicken replied to jimmyoneshot's topic in PHP Coding Help
Keep track of the last post heading and when it changes output a new header Something like this. Just typed off the top of my head. $lastPostId = null; echo '<ul>'; while ($row=$res->fetch()){ if ($lastPostId != $row['rowId']){ if ($lastPostId !== null){ echo '</ul></li>'; //close previous } echo '<li>'.$row['rowId'].'</li><ul>'; $lastPostId = $row['rowId']; } echo '<li>'.$row['comment'].'</li>'; } echo '</ul></li></ul>'; -
Only the boxes that are checked are submitted, so it's as simple as looping over your array of boxes. foreach ($_POST['association'] as $sent_id){ //do something } Since what you want to do is delete them, you could do it all in one query by just using implode() to get a comma separated list of ID's and use that in your query. I would use array_map + intval to ensure they are all integers first to protected against sql injection.
-
That is because there is no place to put your details. That class does not connect to the database on it's own. You do that in your code, then pass the handle to the classes' constructor. Read that comment you pointed out. It tells you to do just that, and even shows you exactly how to do it. Perhaps you will understand better if it is separated out: $dbConnection = new PDO('mysql:dbname=mydb;host=localhost', 'user', 'pass'); $oauth = new PDOOAuth2($dbConnection);
-
PHP/MYSQL broken by the evil browser Internet Explorer
kicken replied to ktroztafy's topic in PHP Coding Help
I agree, that is almost surely the case. Similar to when you have an <img src=""> in your code, the browser will load the page again to try and use it for the image. The reason your only seeing the problem in IE in this case is because IE is the only browser that understands that CSS code. Every other browser will treat that line as an error and ignore it. -
You need to know the proper protocol to communicate with the remote server and properly request the movie file you want. As you've already seen, a standard http request doesn't work, you just get back a text file. I only spent about 5 minutes looking at the exchange between the server and vlc when loading that url, but there seems to be specific headers and values you have to send. VLC shows it as an mmsh:// url so if you read about that protocol you can learn how to implement it (or maybe find an existing solution).
-
Use the second parameter to print_r to have it return a string, rather than output directly. Use <pre> tags not <p> tags to surround it so the white-space is preserved. Neither. Read the manual page I linked, and maybe the setcookie page.
-
It's not just the HTTP protocol. There's another media protocol being used on top of it. Near as I can tell, it's MMSH. If you read up on it and figure out how it works you could probably write some php code to download the file.
-
You'll need to find something that can access the videos over the given protocol. I'm not aware of any php classes or extensions off hand that would handle it. As for the mms:// url's, you could use VLC to download it to a file. Build the appropriate command line, then use exec to run vlc which will then download the video. Ex: $url = 'mms://wmt.stream.co.jp/vod11/tepco/other/1111_01.wmv'; $file = basename($url); $sout = sprintf('#standard{access=file,dst=%s}', $file); $cmd = sprintf('cvlc %s --sout=%s', escapeshellarg($url), escapeshellarg($sout)); exec($cmd);
-
So long as you remove the login flags/other details from your session (so your app considers them logged out), having the cookie stick around is not an issue. My logout consists of: session_destroy(); session_regenerate_id(true); which removes the session data, deletes the session file, and assigns a new ID. If you want to unset the cookie, you need to use setcookie() to delete it. The name of the cookie is the session name (default PHPSESSID) which is returned by the session_name() function.
-
Problem with sending mail with PEAR (Mail/mime.php)
kicken replied to wehappyfew's topic in PHP Coding Help
Function/method names do not start with a $. Only variables. -
You probably need to use a router to split the connection. To know for sure you'd have to ask whoever controls the other end of that cable. As mentioned previously, they may employ some kind of security so only one device can be connected, only one ip assigned. A router would most likely work for you if you want to go get one (assuming you don't have one currently). The only way to know for sure if you can just use your switch is to ask whoever controls that cable how it is setup. Whoever owns the building should know, or be able to tell you who to ask at least.
-
Sanitizing and escaping data is always context dependent. If you have a context that requires a few steps to sanitize something you may want to consider creating a nice function to wrap it all up in one call, but from what you've said so far all you'd really be doing is aliasing mysql_real_escape_string and htmlentities. Those are about all you need to ensure data is safe for a query and safe for display on a web page. The only other output sanitation you may need to use is urlencode, but only when putting data into a link. I really see no point to creating a library of functions. Everything you need is already made in about the simplest api as one could have.
-
<?php if (abs($beyondportal) % 26 == 0 || $beyondportal == 0){ ?> MY CONTENT <?php } ; ?>
-
Just use abs() to make the number non-negative.
-
Does socket_write() block until all data is sent?
kicken replied to DWilliams's topic in PHP Coding Help
TCP guarantees that the packets arrive intact and in order, yes. TCP doesn't take over until the OS's networking stack actually accepts the data. sockets have both a receive and a send buffer. If either of these buffers is full, the OS will reject any new data. So if an application is not reading the data and the read buffer fills up, then the OS will stop accepting new packets (and will tell the remote server this so it stops transmitting). This will cause the remote OS's write buffer to fill up. The write buffer could also fill up if a network condition is preventing packets from being delivered, or they are being delivered too slowly. Once full, the remote OS will stop accepting data for writing. The blocking mode determines what actually happens in the event these buffers are full. If you have blocking enabled, your read/write calls will block execution until the request can be satisfied. For reading that means until enough data is received, and for writing that is until all the given data can be successfully sent (or in either case until an error occurs). In non-blocking mode the read/write calls will give up, and return control back to you. Their return values indicate how much data was successfully read/written so you can take action accordingly. Yes, that is pretty much correct. You will want a separate application buffer for reading and writing data. You'll also have to code your application with the understanding that a read or a write may not complete all at once. For instance, if your reading a packet off the wire, you need to be able to "abort" that read and try again later if the packet is not complete because the data has not all come through yet. The way I handle this typically is by reading data into the read buffer, then using some parsing techniques to run through the buffer til I have a full packet. If I get a full one, I chop the buffer at that point, otherwise it is left intact until the read is tried again. socket_select() is the key to everything. it will inform you when a socket is ready to be read from or written to. Your application should be centered around a loop on the socket_select call. Something like: do { $r=/* add sockets */ $w=/* add sockets */ $e=null; $n = socket_select($r, $w, $e, null, null); if ($n > 0){ foreach ($w as $s){ ///write these sockets } foreach ($r as $s){ //read these sockets } } } while (/* you have sockets available */); -
Are you just plugging the ethernet from your modem into the switch along with your two laptops? If so that will not work. ISP's typically only allow your modem one IP, and it can only forward that to one device. So if you did just plug the modem and the laptops into a switch you'd likely see what your describing. One laptop would work the other wouldn't. If you want to split your internet connect you need to use a router. Plug the modem into the WAN port on the router and your laptops/other devices into the LAN port.