Display Randomized Questions From A Database?
I would like to store 300 questions in a MySQL database, and configure a webpage to display them in groups of 50 at random, then store the responses. Could anyone recommend a script or strategy to do this please?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Randomized Linked Images (urls In .txt)
I need help finding a simple way to get links from a text file and displaying them all linked to an image, and possible randomizing the order too... if you need more info, or can help, it would be much appreciated! I am trying to make it easier on myself because the links change often and it would just save me a lot of time just editeing a list instead of a bunch of html something like: link1 link2 link3 link4 then on refresh: link3 link1 link4 link2 and have the list like: link1 link2 link3 link4 I don't think it should be too difficult but I am new to php and cannot find what I am looking for on php.net.
Generate Randomized Alphanumeric String
I am off trying to see if I can create a ticket reservation system, where a visitor should be able to reserve tickets and get a randomized unique alphanumeric string in uppercase letters with a total of 8 characters. I do not know how to create a script that randomizes letters, from A-Z, and puts it into a string only 8 characters long. To compare it with already stored "randomized" in a database, I guess it is only to do a search in the database. Anyone who has a good advice or script on how to generate what I would like to achieve? Example: GUTIIKLE YYTESVOP PUERBHGA I guess you all know what I am after.
Database Display
I am calling all fields from a table, just to many to call the ones i need. I would like to drop the first 2 from being shown, how can I do that by the code below or do I need to rewrite completely? while ($line = mysql_fetch_array($store_data, MYSQL_ASSOC)) { foreach ($line as $data) { echo $data . ', '; } }
Display Database Record
i have a php script that read from mysql and display then in textbox. I have problem with the way textbox display the data. <input type=text name="package_name" size=20 maxlength=10 value='.$package['package_name'].'> when the package_name is 'china tour' it will only show china in the text box. How can i show all the content of the record?
Display Then Update Sql Database
I have an html drop down list that I have populated from a sql database, a selection is made and the information on the selection retrieved from the database and output in text forms on another page. I want to be able to edit or add data and then update the database. Code for the second page is below. I have echo'd the post variable and it does make it through. From what I understand the post variable is being removed when I submit the second form and so it all fails. How can i sustain the variable from the first page? Code:
Image Display From Database
i have one problem in my programming.there is a table containing some details of the product with its image.. in view section in my php page ,i need to show this image and the rest of the fields in the table in a row...
Don't Display Duplicate Database Entries?
I have a restaurants database that has a lot of restaurants listed with the same name in the same city with only the category changed. This is the code that I have that displays the list of restaurants. Can someone tell me what to add to it so that it will only display one of each restaurant of a certain name? PHP Code:
How To Display Data From Database In Different Web Pages?
When we get data from database by use mssql_query(),suppose the data is very large ,it has many rows, and we want display the data in different web pages like many search engines do, my question is how to do that using the same result without call mssql_query() again?
Trying To Display Image From Mysql Database
I have a mysql db, that holds images. Images are encoded using base64_decode/encode, etc. Image data seems fine. I have a view.php page that is supposed to show the image, and an image.php page that accesses the database, retrives the image data, and then (theoretically) prints the decoded data to the page. below is the view.php page code: problem area the img tag src no worky. What am i missing (having stolen the idea for this from the web!!!! thanks, eric /************************************************** *****************/ <html> <head> <title>Get The Image</title> <link rel="stylesheet" type="text/css" href="css/csssmall.css" /> </head> <body> <center><img src="testimage/Sunset.jpg" width="300" border="1" alt="Image of Sunset"></center> <p class="para-color"><?php echo 'Beautiful Image' ?></p> <br> <center><img src="image.php?img=3" width="200" border="1" alt="Image of Thelma Todd"></center> <p class="para-color"><?php echo ''Nother Beautiful Image' ?></p> </body> </html> /************************************************** ****************/ below is the image.php code: /************************************************** ******************** <?php $dbhost = 'localhost' $dbuser = 'auser' $dbpass = 'apassword' $dbcnx = @mysql_connect($dbhost,$dbuser,$dbpass); if (!$dbcnx) { echo( "connection to database server failed!"); exit(); } if (! @mysql_select_db("portfolio") ) { echo( "Image Database Not Available!" ); exit(); } ?> <?php $img = $_REQUEST["img"]; ?> <?php $result = @mysql_query("SELECT * FROM images WHERE id=" . $img . ""); if (!$result) { echo("Error performing query: " . mysql_error() . ""); exit(); } while ( $row = @mysql_fetch_array($result) ) { $imgid = $row["id"]; $encodeddata = $row["sixfourdata"]; $title = $row['title']; } ?> <?php //echo $encodeddata;print?? echo base64_decode($encodeddata); //echo $prefix . $encodeddata; ?> /************************************************** ***********************
How Do I Display All Database Entries Between Two Dates
I have two dates in a form " startdate" and enddate" when i display the results i would like to show all results between, and including the two dates. how do i do this... this is my current query: My Variables: $userid = $_GET['idr']; $fromdate = $_GET['fromdate']; $todate = $_GET['todate']; The query: $result = mysql_query("SELECT date, status, time, notes FROM timeclock WHERE userid='".$userid."' ORDER BY time");
Function To Display Form From Database!
I'm trying to write a function which gets all the client names from a table and displays them in a drop down list. My function is displaying a form with nothing in! Code:
How To Connect To Mysql Database And Display It In Flash?
i made a code for news that get the data in php and store it in database, then display it using flash.. how to do this.. #news database fields: newstitle newsbody newsdate #variables: $newstitle=$_POST['title']; $newsbody=$_POST['body']; $newsdate=date("Y-m-d");
Display Results From A Database On Multiple Pages
I am new to PHP and Mysql but am really determined to learn these techniques. I have some script that reads and displays results from the databse onto a page. However, I really wish to limit the number of results that are displayed to 10 per page and then have the next/privious links under the results. With these results, the results under the email field should be hyperlinked so that the person viewing the results should double click on the email link and send the person an email. How can i do that? I have to learn this technique. The code is:-
How To Make Display Links From Mysql Database?
i have the following problem and i am breaking my mind on it: I have a mysql database with (id,title,topic,body) in the database i have stored some documents. How can i display a link with only the title of the document stored?(easy one) but... I want to view the whole document in the same page! Let me explain in code: <?php $ip = "localhost"; $user = "kostas"; $password = "kostas"; $basename = "test"; $table ="docs"; $db = mysql_connect($ip, $user, $password); mysql_select_db($basename,$db); $result1= mysql_query("SELECT * FROM $table ORDER BY id DESC LIMIT 5 "); $myrow = mysql_fetch_array($result1); $title = $myrow["title"]; $intro = $myrow["intro"]; $body = $myrow["body"]; ?>
PHP Function To Display A Database / Table Structure?
My webhosts cpanel is down for maintenence, including phpMyAdmin, and I need to view my database structure... Is there any function in PHP to display the database structure (like the "Export" function in PHPMyAdmin)?
Display Items From A Mysql Database In A Table
I am trying to display items from a mysql database in a table but I need it to start a new table row each time multiples of 3 rows of the database table have been displayed like the following example: item 1 item 2 item3 item 4 item 5 item 6 Does anybody know how I can make this work using php.
Submit/Approve/Display Content In Database In PHP?
I want a page where users can submit an image, text, and links and then what is submitted goes to an administration page where such submitted can be approved or declined. And then another page where all the things that have been approved go into a table where the image, text, and links are displayed in a numbered fashion. Here are some picture examples of what I mean: Code:
Display Links From Database, Constructs And Expressions
My users need to enter links into a MySQL text field (along with their text) to a file on the server. For example; the file <a href="somefile.pdf"> somefilea is really big.However, I also want to calculate the file size for them. I've used some of your code to do this, <?php getFileSize('somefile.pdf') ?>, so that the user would enter their text as; the file size <?php getFileSize('cover.pdf') ?> is really big.However, I've been told that putting PHP code in the database field is both problematic and requires the use of eval(). But, I've also been told that I can use something like: the file {link:somefile.pdf} is really big.Then, when the text appears on the page a script looks through the text and constructs an html link from the text {link:somefile.pdf}. But ... how? What would that script look like, any clues?
How To Display Mysql Database Information In Multiple Pages?
how to display mysql database information in multiple pages? i would like to display all my member with consist of 400 people and i wan it list in mulitiple pages, and contain a "delete tick" for me,and when i click the member, can redirect me to member detail imformation. it just similiar to email pages of yahoo inbox.
Display Database Output In Mutli Column Html Table
I am building an HTML form using data from a mysql query. The data to be displayed on the form is 1 column from the db - but multiple rows. Because there are many rows (well, only about 100+) in the table I want to be able to put 2 or 3 (space permitting) rows from the result on each row of the HTML table with a checkbox beside each entry from the db table. The idea is that the user will scroll down the list and check up to 4 or 5 boxes before submitting the form and I didn't want them to have to scroll ALLLL the way to the bottom (100+ rows). I understand how to get data from a db table and put it into an html table, but I cannot figur out how to put more than 1 row from the result on to the same row of the html table. I hope I haven't confused anyone reading this -- If I am way off base with what I am trying to do please give me alternatives. I am trying to avoid paginating the data for a couple reasons a) clicking a next and/or prev button is more hassle than just scolling down a list and b) the data in the column being displayed is only about 35 - 40 characters and it seems to be if i only placed one result row on each html table row, there would be a lot of wasted space.
Several CMS Questions
I am fairly new with PHP but I have used several news posting scripts in the past and none have been simple enough for me. I'm working on creating a site with the following layout, and I need help on a few issues along the way (those questions will be in bold so please check them out, even if you don't want to read everything else!). The basic site layout will use a few "template pages." I.E. main.php and print.php and textonly.php. What they are is fairly self explanatory. The further pages will be accessed in the following manner: http://mysite.net/main.php?content=FAQ Would import a file called faq.php/html/txt (which is the best form for my content?). I also want a news page. Should it be imported in the same way as the other pages (I.E. main.php?content=news)? On every page, I want a "headlines" section with the last 5 recent "headlines" (from the news) and a link to them. On the news page, I want the last 5 news items listed. For my news system I could use MySql or just Flat files (I.E. a file called news.txt which has a uniqueID|author|title|date the uniqueID is the name of a .txt file with the content of that news item). All news items (not just the most recent 5) are found on an archives page, listed by headlines/date/author. Which is better (MySql or Flat files, considering how simple this news system will be Flat may be simpler) and how can I set it up in the way I asked? Also, I created a simple system of PHP to go to different pages depending on the ?content= variable. I want it to go to a specific page if ?content= anything not listed in my variables. Here is what I have, it works except it won't go to google.com if anything "else" is written. How can I fix the code below to work?": PHP Code:
Else If - Questions
I have put togther a script which uploads images and renames them with the article ID, so that image names are always related to the article that is added. But....when calling the individual article to view in a html page I want it so that if there is an image it shows it other wise don't show anything or show a blank pixel image. This is what I have tried and it does show if an image is there, but if the is now image present it shows an image box with missing link. Code:
A Few Questions
Say I wanted to send an HTTP request to a web server on port 80 - would fsockopen or socket_create be better to use? Also, I'm unsure of whether or not stream_set_blocking would be a useful function to use for HTTP queries... any ideas? Finally, the output of this seems a bit surprising: <? ob_start('test'); function test() { return getcwd(); } ?> It displays / while the following displays something like /path/to/file/ <? echo getcwd(); ?>
Pdf Questions
I have a pdf govt issue tax form for non-profits and am trying to write a script that will handle browser based entry of data fields as well as save some info to database It is a tax form and has to be parsed to the pdf file that the govt provides for printing... Am completely stymied on how to pull all the field data, and to post it to the pdf the pdf in question is
Questions About PHP-GTK 1.0
PHP-GTK is the ticket one can take to create cross-platform PHP scripts that load a standalone GUI application with widgets, and then everything else you know about PHP can work in the background via signals (widget events), including database access, etc. Some background for you: http://www.sitepoint.com/article/697 Personally, I can't get it working. Others have, strangely enough. 1. I have RH9. Does anyone have an RH9 RPM out there for PHP-GTK 1? 2. Would it be good for me to install Glade to draw the GUIs and connect the signal handlers faster? I don't have experience with Glade. 3. I tried downloading the 1.0 source and then doing: ../buildconf ../configure make make install but it bombs on ./configure with... ../configure: line 2606: syntax error near unexpected token `debug,' ../configure: line 2606: `PHP_GTK_ARG_ENABLE(debug, whether to include debugging symbols,' 4. I tried the steps recommended in the sitepoint.com web link I posted (above) and it showed the same error, so I commented out the code block starting with if on line 2606 to its following fi. Then, I ran the commands as recommended from the web link, it runs good for awhile and then spits back to me this error: /home/me/installs/php-gtk/build/dynlib.mk:22: /home/me/installs/php-gtk//libs.mk: No such file or directory make: *** No rule to make target `/home/me/installs/php-gtk//libs.mk'. Stop. What's the catch?
PEAR Questions
Can someone explain to me exactly what PEAR is? I've been looking around for different html modules/classes and it keeps coming up, but I can't find anything that actually explains what it's all about. Also, is there a complete list of "PEAR" modules anywhere, organised in one place?
Cron Questions
Just a few questions about cron files: Can I include other files? Eg <?php require(config.php); .... That's pretty much it! I'm running a cron job from DirectAdmin and I keep getting an error email with: /home/aliashos/domains/aliashosting.co.uk/private_html/inc/cron/subscriptioncheck.cron.php: line 1:?php: No such file or directory /home/aliashos/domains/aliashosting.co.uk/private_html/inc/cron/subscriptioncheck.cron.php: line 2: //: is a directory /home/aliashos/domains/aliashosting.co.uk/private_html/inc/cron/subscriptioncheck.cron.php: line 3: //: is a directory /home/aliashos/domains/aliashosting.co.uk/private_html/inc/cron/subscriptioncheck.cron.php: line 4: //: is a directory /home/aliashos/domains/aliashosting.co.uk/private_html/inc/cron/subscriptioncheck.cron.php: line 38: //: is a directory /home/aliashos/domains/aliashosting.co.uk/private_html/inc/cron/subscriptioncheck.cron.php: line 39: syntax error near unexpected token `(' /home/aliashos/domains/aliashosting.co.uk/private_html/inc/cron/subscriptioncheck.cron.php: line 39: `$udq = mysql_query("SELECT * FROM $CustomersTable",$Link) or die(mysql_error());' And if I run the file in my web browser, it works fine! Confused :S
Login Questions
I have 2 books 1.) MySQL/PHP Database Applications and 2.) PHP4 Bible. My problem is that in both books the only way they show how to use a login form is to use the HTTP_AUTH. Which I don't want to use, I want my script to do the login and log out Like VB does. Where or how would I go about doing this? I can enter data into MySQL, but I know i am missing some steps, such as Md5ing the Password and sessions and such. Any info would be great.
IMAP Questions
I've spent hours, days .... weeks(!) reading the manual, but still can't find answers to my questions regarding the use of some IMAP functions and their miscellaneous properties. From now, I'm gonna list all those questions on this thread and see if some of you can provide even partial but useful comments. Question number ONE : imap_setflag_full In imap_setflag_full($mbox, "2,5", "Seen Flagged"); we have the string sequence "2,5" but I fail to understand if it is safe or not to choose any sequence I want regardless of the message structure. For example, if I apply a "Flagged" flag on all incoming messages exclusively at "2,5", is it possible that I could overwrite some precious information in that particular place? What are the implications of such a method?
Questions About Config.php
We all know its effective to create one central config file say "config.php" that contains the required configuration variables. I had seen the configuration is done by three ways: 1> By simply using variables ex $dbHost = ""; etc 2> By using associative arrays ex $setting['dbHost'] = ""; etc 3> By defining constants ex define("DB_HOST",""); etc My Question? Which one to use and why in config.php for creating the configuration file?
A Questions About Mysql_fetch_array()
whenever i use this, i'm leaving out one item from the array. in other words, one row from the table i'm querying won't show up. i'm new at php, and this is probably a simple thing, but please help of you can. here's an example that leaves out the most recent submission: $query = "SELECT topic, message, author, DATE_FORMAT(posted, '%M %e, %Y') AS d FROM messageboard ORDER BY posted DESC"; $result = @mysql_query ($query); $row = mysql_fetch_array($result, MYSQL_ASSOC); while ($row = mysql_fetch_array ($result, MYSQL_ASSOC) ) { echo"<p> {$row['topic']}<br> {$row['message']} <br>Posted by {$row['author']} on {$row['d']} <br>"; }
Pcntl_fork Questions
php.net's docs on pcntl_fork aren't exactly clear on how to spawn multiple child processes... i tried something like this, but it didn't seem to work: <? $pid1 = pcntl_fork(); $pid2 = pcntl_fork(); $pid3 = pcntl_fork(); if ($pid1) print "test; if ($pid2) print "test2"; if ($pid3) print "test3"; ?> any ideas why it didn't work?
PHP GTK Option Questions
Before I invest more time in researching and testing I am curious if anyone knows for certain if a PHP_GTK application running on a Windows machine can communicate and interface with a remote database SECURELY? My plan involves creating a support system which would be a standalone application on a Windows Workstation. This application would query data from a remote database SECURLY and then support personal would be able to modify, edit, etc. data from the PHP_GTK application which would in turn update data in the remote database, again securely. Can a PHP_GTK application support this, security being the biggest concern?
Questions About Sessions
First, just wanted to say that I found what I thought was a very helpful tutorial on sessions in case anyone out there has questions on them: I've been using sessions for quite some time but only after reading this do I really understand what is going on on both the client and server side. Unfortunately, I still have some unanswered questions after reading it, as it is pretty basic and gives a quick intro to sessions. For testing purposes, I turned off all cookies in IE and attempted to sign into my site on my local host, which uses sessions for signing in. In addition, session.use_trans_sid = 0 in my ini file. I can't figure out how, but somehow my scripts all still work and I am able to login fine, even though cookies are disabled, as well as trans sid. How is my session id being passed, as my understanding is these are the 2 possible methods? There is no sessid propagated through the URL either, so it is not through a get variable. Also, I looked in my sessiondata folder and found a bunch of session data. When I physically log out and kill a session, it removes it from the folder. However, when I just close the browser window, it does not remove the data from the folder. Reopening the browser right away results in a new session and requires the user to login again, but the old data from the previous session is still there. I checked my ini, and found the default: ; After this number of seconds, stored data will be seen as 'garbage' and ; cleaned up by the garbage collection process. session.gc_maxlifetime = 1440 But this isn't working as far as I can tell because I have session files from days ago, and according to this it should be deleted after 24 minutes.
PHP Interview Questions
I have reasonable PHP experience, but not yet a guru. I am going to an interview this week for a PHP role, they develop a portal system used by governments departments to create a common entry point for state government services. I have been advised they will be questioning my skill level on PHP, and although my strengths are in Java (which they may use me for also) I was just wondering what kinds of questions you all may have come across in the interview, just so I get a feel for what to expect.
Questions About GD And Images
I have a system where admins can upload photos and images....the original photo as well as the thumbnail...At first sight, I had 2 fields, one for the image and one for the thumbnail...however, I was thinking about having only one field while the image should be proccessed by the "submit" script afterwards in order to create the thumbnail aytomatically in the selected folder (/pictures/thumbs/) while storing the original image in the /pictures/ folder... In the first system I created (2 fields), both images were uploaded in a selected folder while their extensions(names) were stored in the Database...however...if I use GD library to create the new system the whole thing changes...Images are not uploaded but stored directly in the database as strings and called afterwards as images...for instance, the original photo is stored in the database while the automatically created thumbnail proccessed by GD, (opened as text...croped...etc etc.) and also stored in DB as text...Am I right?
PHP Interview Questions
We have collected Questions and answers for interviews after a long effort and you study these questions and its answers freely our website. If you have any query regarding to interview you contacts with us we have reply your problem as soon as possible. I am very Thank full to you.
Questions About Curl
I was looking at the various cURL options and have a few questions. CURLOPT_HTTPPROXYTUNNEL's being set to true is supposed to tunnel through a given HTTP proxy. Afaik, tunneling is only possible when the CONNECT method is used. Is that correct? Also, if it is... one can normally tunnel through as many HTTP proxies supporting CONNECT as they see fit. Does cURL only let you tunnel through one? CURLOPT_PORT's value is described as "an alternative port number to connect to", however, CURLOPT_URL already allows a URL to be added. Does this mean that if it can't connect on that port, it'll try to connect on this port?
Session Questions
I have a question regarding the usage of sessions and cookies. I'm still a fairly new developer, but have built quite a few login-driven applications using MySQL for the backend and PHP for the front end. When I have a login, I generally do the standard algorithm - Check the DB for a matching UN/PW, set a session variable as true (or jsut set the username as a session var) and then check on if the session['username'] var is set. If it's set, they're logged in, if it's not they're not and I redirect back to login. My question has come up recently as I've seen many PHP developers using setcookie() and running their code off of this. I'm using the following method if there has been a matching un/pw combination found in the DB: if($totalRows != 0){ $_SESSION['username'] = $row['usernameFromDB']; } Then, in my include file to check, I'll say something like: if(!isset($_SESSION['username'])){ header("Location: login.php"); }
Two Header Questions
Is it possible to generate an export file and still showing different HTML page? I have a page and when the user clicks on a link I generate export file (with header and data after header) and the page remains the same. It would be nice if I could show another page, like message "data generated!". And I have another question. I have the following code for sending export file: header("Content-Disposition: attachment; filename=export.txt"); header("Content-Type: application/octetstream"); header("Pragma: no-cache"); header("Expires: 0"); echo $Data; but when the Save as dialog appears I get filename "export.txt.php". What must I do to get the right filename "export.txt"?
Speed Questions
i was trying to append a % before any occurance of either abc, abd, or abe, in a string. which would be faster?: $string = str_replace("abc","%abc",$string); $string = str_replace("abd","%abd",$string); $string = str_replace("abe","%abe",$string); or $string - preg_replace("/(abc|abd|abe)/","%$1",$string); php.net says that preg_replace is slower than one str_replace, but for multiple ones, it seems like it would gain a slight speed advantage. also, exactly how would the following to code segments compare, speed wise? for ($num=0;$num<$length;$num++) { $array1[] = $num; $array2[] = $num; } for ($num=0;$num<$length;$num++) $array1[] = $num; for ($num=0;$num<$length;$num++) $array2[] = $num; it seems like the first one should require 3*$length operations, whereas the first one would require 4*$length operations, although i'm not 100% sure on that.
Session Questions
I currently manage all my sessions through MySQL tables, but obviously this means database overhead for every single page. I would like to move to PHP sessions but I'm not sure they do the job. I'm sure you can all imagine how you would implement database-based sessions, i.e. generate and store a unique identifer with the user data, and pass this ID from page to page. On loading the page, get the user data associated with that ID. I would like to do this in PHP. However, I'm having problems with the following: 1. Uniqueness. If someone with the account 'Dave' logs in on a phone in Brazil, it should invalidate the session anyone else using that same account, on any device, anywhere. There should only be one session per account at any time. 2. Overwriting. On no account must anyone overwrite Dave's session and become that user. This seems to be a problem in my test attempts for no good reason (and the other user is on a different machine!) 3. Destruction. I, the manager, want to be able to destroy individual sessions ("boot") at will, if possible. Can this be achieved, or should I stick to doing it the MySQL way (or maybe there's a better way)?
PHP5 Questions
I noticed there's an error in PHP when it receives form data. It seems to precede various characters with "". I was wondering if that's about to get fixed in PHP5, or already is fixed in PHP4? (Or is this somehow not an error?) Also, I was wondering when/ if PHP will include more object-oriented functions, like $myString.replace($find, $replaceWith). (I sometimes wonder if I need to use the first or second or third parameter or what and it takes some more seconds to check PHP.net.) Next, are there any plans to remove the "$" in front of variables? Also: will XPath be supported internally/ by standard libraries (I use a special library not part of PHP and it could be a little faster)? Will there be real private members/ functions in PHP5 when using classes/ objects? (And any plans to drop "$this->", not that it's really bad?)
|