Jump to content


alapimba

Member Since 15 Nov 2006
Offline Last Active Aug 29 2014 11:47 AM

Posts I've Made

In Topic: Loop Throught Sql Results And Don't Print Repeated Data

23 November 2012 - 11:11 AM

everything worked perfect for my needs.
Thanks a lot for your help :)

In Topic: Loop Throught Sql Results And Don't Print Repeated Data

23 November 2012 - 10:00 AM

nice seems simple.
i'll try to use on my real data that it's a bit more complex.

the array can be generated on a while($row = mysql_fetch_assoc($result)) loop?

In Topic: Loop Throught Sql Results And Don't Print Repeated Data

23 November 2012 - 05:21 AM

Hi

I just realized that my example was too simple for my final needs :-\

i understand that example above.

but in my work i need it a bit more complex..

imagine that instead of phone numbers only i have area code and phone numbers (in separate columns).

How can i print it like:
name<br>
area code - phone number <br>
area code - phone number2 <br>
area code - phone number3 <br>
e-mail

In my real example this tables have books and authors.

some books have more then 1 author..

and i need to print it like this:

<div id="contentdiv">
<?php
$i = 0;
do {
?>
<?php				
$i = $i + 1;
?>
			 <div id="contentdiv<?php echo $row_rs_livros2['id_li']; ?>" <?php if ($i <= 1) { echo "style='display: block;'"; } else { echo "style='display: none;'"; }?>>
				 <a href="livros.php?id_li=<?php echo $row_rs_livros2['id_li']; ?>" class="titulos_vermelho_livros"><?php echo $row_rs_livros2['livro']; ?></a><br/><br/>
				
				
				 <?php //here i'll have more then 1 author sometimes ?>
				 <span class="texto"><a href="autores.php?id=<?php echo $row_rs_livros2['id']; ?>" class="titulos_livros"><?php echo $row_rs_livros2['nome']; ?><?php echo $row_rs_livros2['apelido']; ?></a><br>
	
				
				
	 <?php	
	 mb_internal_encoding("UTF-8");
	 $str = $row_rs_livros2['texto'];
	 $limit = 300; //Specify the length of the new substring
	 if (substr($str, $limit, 1) != ' ' && ($l = mb_strrpos(mb_substr($str, 0, $limit), ' '))) {
		 echo mb_substr($str, 0, $l);
	 } else {
		 echo mb_substr($str, 0, $limit);
	 }
	 ?>(...)<br />
	
				 <a href="livros.php?id_li=<?php echo $row_rs_livros2['id_li']; ?>" class="style3">ver mais ยป</a></span></div>
				 <?php } while ($row_rs_livros2 = mysql_fetch_assoc($rs_livros2)); ?>
</div>
</div>

at the moment my query is still this:
SELECT autores.id, autores.nome, autores.apelido, livros.id_li, livros.texto, livros.pdfs, livros.foto, livros.foto_grande, livros.livro, livros.ordem, ids.id_livro FROM autores INNER JOIN ids ON autores.id=ids.id_autores INNER JOIN livros ON ids.id_livro=livros.id_li WHERE estado = 'on' ORDER BY livros.ordem

In Topic: Loop Throught Sql Results And Don't Print Repeated Data

22 November 2012 - 01:56 PM

These kinds of issues are avoidable with proper table setup.

`id_name` and `email` should not be repeated as you have shown above. You need to normalize your database.

TABLE `users`

`id_name`, `email`

TABLE `phone`

`phone_number`

This is just pseudo setup as I don't know your overall schema. But, for example, if you're using `email` as the username for a user, then that value would have to be unique.

Your best to separate the data that can have multiple variances into a separate table and create a relationship table and/or a simple JOIN.

Sorry if that comes off as confusing, but table setup is really the best solution to your problem from what I can see.



I understand a bit what you said but at the moment my tables are already so big that it will mess with other stuff on the site if i decided to change it now. (it's not a 3 column table as the example that i show...)
in reallity it's 3 tables with inner joins that gives that kind of output.

i have one table with id_username and e-mail
i have another with id_username_phone and phone number
and then i have a 3rd table with id_username and id_username_phone to connect everything.

the query that i use gives that kind of result.

Now i need to organize it with php... theres no way?

In Topic: Text hidden behind div on firefox

14 September 2012 - 09:01 AM

i'm making some test and at the moment with a change that i did it kinda fixed but i had to remove the css styles for the font.
please try again as the problem is back on :)

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com