473,386 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How do I call a random quote using PHP and javascript?

4
I've been trying to replace my old PHP/iframe random quotes script with a PHP/javascript without success.

http://www.just-quotes.com/wow/random.php

<script scr="http://www.just-quotes.com/wow/random.php" type="text/javascript"></script>

The script "random.php" works correctly and pulls a random quote from the text file but everything I've tried fails to produce a quote in the HTML page.

Help is needed!
Feb 21 '07 #1
6 2401
AricC
1,892 Expert 1GB
I've been trying to replace my old PHP/iframe random quotes script with a PHP/javascript without success.

http://www.just-quotes.com/wow/random.php

<script scr="http://www.just-quotes.com/wow/random.php" type="text/javascript"></script>

The script "random.php" works correctly and pulls a random quote from the text file but everything I've tried fails to produce a quote in the HTML page.

Help is needed!
With PHP in your HTML page you need to include the script like this:
Expand|Select|Wrap|Line Numbers
  1. <? include('some_file.php'); ?>
  2.  
If your script displays something it will show where you include the php file. If I am missing something let me know we can move this to the PHP forum.

Aric
Feb 22 '07 #2
RTB
4
With PHP in your HTML page you need to include the script like this:
Expand|Select|Wrap|Line Numbers
  1. <? include('some_file.php'); ?>
  2.  
If your script displays something it will show where you include the php file. If I am missing something let me know we can move this to the PHP forum.

Aric

This script will also be used externally from other sites.

RTB
Feb 22 '07 #3
acoder
16,027 Expert Mod 8TB
It's difficult to replicate the behaviour without seeing the PHP code, but you can try the following:
1) Get the quotes from the PHP (a database I assume).
2) Put them in a Javascript array, quotes.
3) Then use Math.random, e.g:
Expand|Select|Wrap|Line Numbers
  1. index = Math.floor(Math.random() * quotes.length);
4) Use index to get your quote:
Expand|Select|Wrap|Line Numbers
  1. document.write(quotes[index]);
and you're done!
Feb 23 '07 #4
RTB
4
It's difficult to replicate the behaviour without seeing the PHP code, but you can try the following:
1) Get the quotes from the PHP (a database I assume).
2) Put them in a Javascript array, quotes.
3) Then use Math.random, e.g:
Expand|Select|Wrap|Line Numbers
  1. index = Math.floor(Math.random() * quotes.length);
4) Use index to get your quote:
Expand|Select|Wrap|Line Numbers
  1. document.write(quotes[index]);
and you're done!
The quotes are in a text file and the script is also used by other web sites.
Feb 23 '07 #5
iam_clint
1,208 Expert 1GB
why not use an iframe
Feb 23 '07 #6
RTB
4
why not use an iframe
The iframe has fixed sizing and I needed to have it more flexible.

I've since got it working much better.

http://www.just-quotes.com/quotes_service.html

Expand|Select|Wrap|Line Numbers
  1. <center><table width="100%"><tr><td>
  2. <script type="text/javascript" src="http://www.just-quotes.com/wow/random_quotes.php"></script>
  3. <noscript>Your browser does not support JavaScript!</noscript>
  4. <div align="right">By <a href="http://www.just-quotes.com" target="_blank">Just-Quotes.com</a></div>
  5. </td></tr></table></center>
Mar 10 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: Thomas Mlynarczyk | last post by:
I remember there is a programming language where you can initialize the random number generator, so that it can - if you want - give you the exactly same sequence of random numbers every time you...
2
by: gene | last post by:
I have some javascript code that displays random images in random places on the page by making changes to the document's css. This works in Safari and IE, but I can't get it to work on Mozilla. ...
5
by: Luke | last post by:
Hello, I am the administrator for http://www.nickberg.org - Nick is the man who was recently beheaded in Iraq. He was a very ingenious man - once for my birthday had gave me a small box...
4
by: lharby | last post by:
I'm hoping this is very simple. I am currently using a random quote generator on our intranet. I have 17 quotes, when I add in an 18th and change the makeArray number the code seems not to work....
14
by: avanti | last post by:
Hi, I need to generate random alphanumeric password strings for the users in my application using Javascript. Are there any links that will have pointers on the same? Thanks, Avanti
7
by: Brian | last post by:
Hi there I have been looking for a script that can randomly rotate 8 different images on 1 page. I used to have a script that did this but can't find it now. I have found loads of script that...
9
by: Tuxedo | last post by:
I'd like to reorganize the third, fourth, fifth and sixth, as well as any elements thereafter in an array in random order: var a = new...
1
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I generate a random integer from 1 to N?...
34
by: Johannes Baagoe | last post by:
About Math.random(), ECMA 262 just says "Returns a number value with positive sign, greater than or equal to 0 but less than 1, chosen randomly or pseudo randomly with approximately uniform...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.