Jump to content

increasing numbers???


ericburnard

Recommended Posts

Hi there i have the following javascript

 

<table width=150><tr><td>
  <script language="JavaScript">
      //Link[nr] = "position [0 is menu/1 is item],Link name,url,target (blank|top|frame_name)"
  var Link = new Array();
  Link[0] = "0|Home";
  Link[1] = "1|Home|http://www.javascriptsource.com|";
  Link[2] = "1|More Scripts|http://www.javascript.com|";
  Link[3] = "1|Contact|http://www.javascriptsource.com/contact-us.html|";
  Link[4] = "1|Traffic|http://www.thecounter.com|";
  Link[5] = "0|Access";
  Link[6] = "1|Login|Login.asp|";
  Link[7] = "1|Logout|Logout.asp|"
  Link[8] = "0|Scripts";
  Link[9] = "1|Asp|http://www.javascriptsource.com|";
  Link[10] = "1|JavaScript|http://www.javascriptsource.com|";
  Link[11] = "0|Links";
  Link[12] = "1|JavaScript sites|http://www.javascripts.com|blank";

  startup(4);
  </script>
</td></tr></table>

 

As you can see the link number increases every time. I have put what i need of this code into my php -

 

<?
include('mheader.html');
include ('db.php');

$cookie=$_COOKIE["cusername"];

mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM blog ORDER BY id DESC";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<table width=150><tr><td>
  <script language='JavaScript'>
      //Link[nr] = 'position [0 is menu/1 is item],Link name,url,target (blank|top|frame_name)'
  var Link = new Array();";
   
$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$subject=mysql_result($result,$i,"subject");
$blog=mysql_result($result,$i,"blog");
$date=mysql_result($result,$i,"date");

echo "
  Link[0] = '0|$id : $subject : $date';
  Link[1] = '1|$blog|$blog|';";

$i++;
};

echo "startup(4);
  </script>
</td></tr></table><BR><BR>";
  
?>

 

The only problem i have now is that when the script repeats itself its just using the numbers 0 and 1 what i need it to do is 0,1 then the next repeat 2,3 the next 4,5 and so on im not to sure how to go about doing this??

Any help would be great.

Thanks again

Eric

Link to comment
Share on other sites

Try:

<?php
include('mheader.html');
include ('db.php');

$cookie=$_COOKIE["cusername"];

mysql_connect($host,$username,$password) or die(mysql_error());
mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM blog ORDER BY id DESC";
$result=mysql_query($query) or die(mysql_error());

$num=mysql_num_rows($result) or die(mysql_error());

echo "<table width=150><tr><td>
  <script language='JavaScript'>
      //Link[nr] = 'position [0 is menu/1 is item],Link name,url,target (blank|top|frame_name)'
  var Link = new Array();";

while ($row = mysql_fetch_array($result)) {

echo "
  Link[0] = '0|{$row['id']} : {$row['subject']} : {$row['date']}';
  Link[1] = '1|{$row['blog']}|{$row['blog']}|';";
};

echo "startup(4);
  </script>
</td></tr></table><BR><BR>";
  
?>

 

By the way, you never used the date column. Did you mean to say blog|date or blog|blog back-to-back?

Link to comment
Share on other sites

That does not solve the OP's problem, in fact it has the same problem -- you are explicitly setting the index. Try this:

<?php
include('mheader.html');
include ('db.php');

$cookie=$_COOKIE["cusername"];

mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM blog ORDER BY id DESC";
$result=mysql_query($query);
echo "<table width=150><tr><td>
  <script language='JavaScript'>
      //Link[nr] = 'position [0 is menu/1 is item],Link name,url,target (blank|top|frame_name)'
  var Link = new Array();";
$i = 0;
$tmp = array();
while ($rw = mysql_fetch_assoc($result)) {   
    $tmp[] = 'Link[' . $i++ . "] = '0|" . $rw['id'] . ' : ' . $rw['subject'] . ' : ' . $rw['date'] . "'";
    $tmp[] = 'Link[' . $i++ . "] = '1|" . $rw['blog'] . '|' . $rw['blog'] . "|'"; 
};
echo implode("\n",$tmp) . "\n";	
echo "startup(4);
  </script>
</td></tr></table><BR><BR>";
  
?>

 

Ken

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.