Jump to content

[SOLVED] Please Help! :(


Marsha

Recommended Posts

Hey, How would I collect multiple things from a database with this code:

for($i=0; $i<sizeof($row['title']); $i++ );

echo '<script type="text/javascript">

function ShowPopup(hoveritem)

{

hp = document.getElementById("hoverpopup' . $i . '");

 

// Set popup to visible

hp.style.visibility = "Visible";

}

 

function HidePopup()

{

hp = document.getElementById("hoverpopup' . $i . '");

hp.style.visibility = "Hidden";

}

</script>';

 

echo '<td align="center"><a id="hoverover"

 

style="cursor:default;" onMouseOver="ShowPopup(this);"

 

onMouseOut="HidePopup();">',$row['title'],'</a><br /><body><div id="hoverpopup' .

 

$i . '" style="visibility:hidden; position:absolute;

 

z-index:1; top:300; left:20; height: 71px; width: 99px">' . $i .

 

'</div></body>';

 

I was recommended the "for" code at the top but it hasn't worked :s

I was told to use this:

<?php for($i=0; $i<sizeof($records); $i++ ): ?>

  <a onMouseOver="ShowPopup('hoverpopup<?php echo $i; ?>');" onMouseOut="HidePopup('hoverpopup<?php echo $i; ?>');">link</a>

 

  <div id="hoverpopup<?php echo $i; ?>">

    <!-- popup stuff -->

  </div>

<?php endfor; ?>

HELP :(

Link to comment
https://forums.phpfreaks.com/topic/174430-solved-please-help/
Share on other sites

Hi Marsha,

 

Could you be a little bit more specific?  The code you've supplied is basically echoing out some Javascript and a link for each row being pulled from the database.

 

Is this what you want to ahieve?  Is the above not working?  Are you receiving any error messages?

Link to comment
https://forums.phpfreaks.com/topic/174430-solved-please-help/#findComment-919403
Share on other sites

You may have to double check the javascript (not my strong point), but first try this;

 

<?php
echo '<script type="text/javascript">
function ShowPopup(hoveritem)
{
hp = hoveritem;

// Set popup to visible
hp.style.visibility = "Visible";
}

function HidePopup(hoveritem)
{
hp = hoveritem;
hp.style.visibility = "Hidden";
}
</script>';

for($i=0; $i<sizeof($row['title']); $i++ )
{

echo '<td align="center"><a id="hoverover"

style="cursor:default;" onMouseOver="ShowPopup(this);"

onMouseOut="HidePopup(this);">',$row['title'],'</a><br /><body><div id="hoverpopup' .

$i . '" style="visibility:hidden; position:absolute;

z-index:1; top:300; left:20; height: 71px; width: 99px">' . $i .

'</div></body>';
}

 

Also;

 

sizeof($row['title'])

 

can you var_dump($row['title']) to make sure you're using the correct function here.

Link to comment
https://forums.phpfreaks.com/topic/174430-solved-please-help/#findComment-919474
Share on other sites

What value is returned when you echo $i?  In your example above you have:

 

<div id="hoverpopup<?php echo $i; ?>">

 

Does that number change when you run the script?

No, I changed all of the "$i"'s to $row['title'] just to check and all of the titles changed to 1, and I hovered over them, and it gave me 1 on all of them

 

You may have to double check the javascript (not my strong point), but first try this;

 

<?php
echo '<script type="text/javascript">
function ShowPopup(hoveritem)
{
hp = hoveritem;

// Set popup to visible
hp.style.visibility = "Visible";
}

function HidePopup(hoveritem)
{
hp = hoveritem;
hp.style.visibility = "Hidden";
}
</script>';

for($i=0; $i<sizeof($row['title']); $i++ )
{

echo '<td align="center"><a id="hoverover"

style="cursor:default;" onMouseOver="ShowPopup(this);"

onMouseOut="HidePopup(this);">',$row['title'],'</a><br /><body><div id="hoverpopup' .

$i . '" style="visibility:hidden; position:absolute;

z-index:1; top:300; left:20; height: 71px; width: 99px">' . $i .

'</div></body>';
}

 

Also;

 

sizeof($row['title'])

 

can you var_dump($row['title']) to make sure you're using the correct function here.

I will try that now, Thank you :)

Link to comment
https://forums.phpfreaks.com/topic/174430-solved-please-help/#findComment-919524
Share on other sites

Sure can :)

http://www.rs-trainsim.co.uk/forums/

You'll need to register (No activation required)  but once you have, Click downloads, and It is right there, it is the "Recent Downloads" and "Top Rated" section.

 

The code that is active now is the one that gevans quoted apart from I changed the small bit from:

<div id="hoverpopup' .

 

  $i . '" style="visibility:hidden; position:absolute;

 

  z-index:1; top:300; left:20; height: 71px; width: 99px">' . $i .

 

  '</div></body>';

}

To:

<div id="hoverpopup' .

 

  $i . '" style="visibility:hidden; position:absolute;

 

  z-index:1; top:300; left:20; height: 71px; width: 99px">' . $row['title'] . '</div></body>';

}

Link to comment
https://forums.phpfreaks.com/topic/174430-solved-please-help/#findComment-919547
Share on other sites

here's some updated code;

 

<?php
echo '<script type="text/javascript">
function ShowPopup(hoveritem)
{
hp = document.getElementById(hoveritem);

// Set popup to visible
hp.style.visibility = "Visible";
}

function HidePopup(hoveritem)
{
hp = document.getElementById(hoveritem);
hp.style.visibility = "Hidden";
}
</script>';

for($i=0; $i<sizeof($row['title']); $i++ )
{

echo '<td align="center">
	<a id="hoverover" style="cursor:default;" onMouseOver="ShowPopup(\'hoverpopup'.	$i .'\');" onMouseOut="HidePopup(\'hoverpopup'.	$i .'\');">',
		$row['title'],
	'</a>
	<br />
	<div id="hoverpopup'. $i .'" style="visibility:hidden; position:absolute;z-index:1; top:300; left:20; height: 71px; width: 99px">
		'. $i .'
	</div>';
}

 

Also the content of each div seems to be a number!?

Link to comment
https://forums.phpfreaks.com/topic/174430-solved-please-help/#findComment-919549
Share on other sites

hehe, well I set it to numbers for the div because surely if it worked it would show 0, 1, 2, 3, 4 etc... right? but yes when It does come up like that (when it works) I will change the ' . $i . ' at the end to $row['title'] so that it pops up with the name.

 

The code you just put up has helped, now when you hover over it, It comes up with 0, and when you stop hovering, the 0 goes and the title is still visible, so it's correct now but the Numbers are not increasing :/

Link to comment
https://forums.phpfreaks.com/topic/174430-solved-please-help/#findComment-919562
Share on other sites

Yes to both, http://www.rs-trainsim.co.uk/forums/

You'll need to register (No activation required)  but once you have, Click downloads, and It is right there, it is the "Recent Downloads" and "Top Rated" section.

 

and Yes, More than one title is stored on a database, the website picks out 8 titles, 4 of which are for a top rated download, and the other 4 are the most recently added download titles.

 

Link to comment
https://forums.phpfreaks.com/topic/174430-solved-please-help/#findComment-919572
Share on other sites

You're not using my exact update. It's repeating the javascript which is shouldn't be in the loop...

 

<?php
echo '<script type="text/javascript">
function ShowPopup(hoveritem)
{
   hp = document.getElementById(hoveritem);

   // Set popup to visible
   hp.style.visibility = "Visible";
}

function HidePopup(hoveritem)
{
   hp = document.getElementById(hoveritem);
   hp.style.visibility = "Hidden";
}
</script>';

for($i=0; $i<sizeof($row['title']); $i++ )
{

   echo '<td align="center">
      <a id="hoverover" style="cursor:default;" onMouseOver="ShowPopup(\'hoverpopup'.   $i .'\');" onMouseOut="HidePopup(\'hoverpopup'.   $i .'\');">',
         $row['title'],
      '</a>
      <br />
      <div id="hoverpopup'. $i .'" style="visibility:hidden; position:absolute;z-index:1; top:300; left:20; height: 71px; width: 99px">
         '. $i .'
      </div>';
}

 

Look carefully at that, and if you have to copy/paste it in parts make sure the javascript is out of the loop.

 

If you get the same problem, please paste more code.

Link to comment
https://forums.phpfreaks.com/topic/174430-solved-please-help/#findComment-919579
Share on other sites

You also seem to be printing out more data within the for loop...

 

<span class="smalltext">
Rating: (None)
<br />
Downloads: 1
<br />
Views: 2
<br />
Filesize: 7.01MB
<br />
Date: <b>Today</b> at 04:03:27 PM
<br />
Comments (<a href="http://rs-trainsim.co.uk/forums/index.php?action=downloads;sa=view;down=124">0</a>)
<br />
By: <a href="http://rs-trainsim.co.uk/forums/index.php?action=profile;u=219">The Trainspotter</a>
<br />
</span>

 

If you can show the full script it will be a lot easier

Link to comment
https://forums.phpfreaks.com/topic/174430-solved-please-help/#findComment-919589
Share on other sites

ok, try replacing the whole function with this;

 

function MainPageBlock($title, $type = 'recent')
{
global $db_prefix, $scripturl, $txt, $modSettings, $boardurl, $context, $user_info;


if (!$context['user']['is_guest'])
	$groupsdata = implode($user_info['groups'],',');
else 
	$groupsdata = -1;	


$maxrowlevel = 4;

echo '<script type="text/javascript">
function ShowPopup(hoveritem)
{
	hp = document.getElementById(hoveritem);

	// Set popup to visible
	hp.style.visibility = "Visible";
}

function HidePopup(hoveritem)
{
	hp = document.getElementById(hoveritem);
	hp.style.visibility = "Hidden";
}
</script>';

echo '<table cellspacing="0" cellpadding="5" border="0" align="center" width="90%" class="tborder">
<tr class="titlebg">
<td align="center" colspan="4">', $title, '</td>
</tr>
';

//Check what type it is
$query = ' ';
$query_type = 'p.ID_FILE';
switch($type)
{
	case 'recent':
		$query_type = 'p.ID_FILE';
		break;

	case 'viewed':
		$query_type = 'p.views';
		break;

	case 'mostcomments':
		$query_type = 'p.commenttotal';
		break;

	case 'mostdownloaded':
		$query_type = 'p.totaldownloads';
		break;

	case 'toprated':
		$query_type = 'p.rating';
		break;
}

$query = "SELECT p.ID_FILE, p.commenttotal, p.totalratings, p.rating, p.filesize, p.views, p.title, p.ID_MEMBER, m.realName, p.date, p.description,
p.totaldownloads 
FROM {$db_prefix}down_file as p
LEFT JOIN {$db_prefix}members AS m  ON (m.ID_MEMBER = p.ID_MEMBER)
LEFT JOIN {$db_prefix}down_catperm AS c ON (c.ID_GROUP IN ($groupsdata) AND c.ID_CAT = p.ID_CAT)
WHERE p.approved = 1 AND (c.view IS NULL || c.view =1) GROUP by p.ID_FILE  ORDER BY $query_type DESC LIMIT 4";

// Execute the SQL query
$dbresult = db_query($query, __FILE__, __LINE__);
$rowlevel = 0;
$i = 0;
while($row = mysql_fetch_assoc($dbresult))
{
	if ($rowlevel == 0)
		echo '<tr class="windowbg2">';


	echo '<td align="center">
	<a id="hoverover" style="cursor:default;" onMouseOver="ShowPopup(\'hoverpopup'.   $i .'\');" onMouseOut="HidePopup(\'hoverpopup'.   $i .'\');">',
	$row['title'],
	'</a>
	<br />
	<div id="hoverpopup'. $i .'" style="visibility:hidden; position:absolute;z-index:1; top:300; left:20; height: 71px; width: 99px">
	'. $i .'
	</div>';


	echo '<span class="smalltext">';
	if (!empty($modSettings['down_set_t_rating']))
	echo $txt['downloads_form_rating'] . GetStarsByPrecent(($row['totalratings'] != 0) ? ($row['rating'] / ($row['totalratings']* 5) * 100) : 0) . '<br />';
	if (!empty($modSettings['down_set_t_downloads']))
	echo $txt['downloads_text_downloads'] . $row['totaldownloads'] . '<br />';

	if (!empty($modSettings['down_set_t_views']))
	echo $txt['downloads_text_views'] . $row['views'] . '<br />';
	if (!empty($modSettings['down_set_t_filesize']))
	echo $txt['downloads_text_filesize'] . format_size($row['filesize'], 2) . '<br />';
	if (!empty($modSettings['down_set_t_date']))
	echo $txt['downloads_text_date'] . timeformat($row['date']) . '<br />';
	if (!empty($modSettings['down_set_t_comment']))
	echo $txt['downloads_text_comments'] . ' (<a href="' . $scripturl . '?action=downloads;sa=view;down=' . $row['ID_FILE'] . '">' . $row['commenttotal'] . '</a>)<br />';
	if (!empty($modSettings['down_set_t_username']))
	{
	if ($row['realName'] != '')
	echo $txt['downloads_text_by'] . ' <a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">'  . $row['realName'] . '</a><br />';
	else
	echo $txt['downloads_text_by'] . ' ' . $txt['downloads_guest'] . '<br />';
	}
	echo '</span></td>';


	if ($rowlevel < ($maxrowlevel-1))
	$rowlevel++;
	else
	{
	echo '</tr>';
	$rowlevel = 0;
	}
	$i++;
}
if ($rowlevel !=0)
{
echo '</tr>';
}

echo '
</table><br />';

mysql_free_result($dbresult);

}

Link to comment
https://forums.phpfreaks.com/topic/174430-solved-please-help/#findComment-919631
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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